![]() |
|
A code alternative for finding an empty slot properly - Printable Version +- open.mp forum (https://forum.open.mp) +-- Forum: General (https://forum.open.mp/forumdisplay.php?fid=19) +--- Forum: Programming (https://forum.open.mp/forumdisplay.php?fid=56) +--- Thread: A code alternative for finding an empty slot properly (/showthread.php?tid=2828) |
A code alternative for finding an empty slot properly - Amr - 2024-07-19 Finding the First Empty Slot in an Array Objective: To determine the index of the first empty slot in a 0-indexed array Arr of size 1024, with an additional precaution against potential overflow. Explanation: Code: int SizeArr = 1024; // Size of the array
int Arr[SizeArr + 1]; // Array with additional slot
int i = 1; // Initialization of index i
while (Arr) // Loop until an empty slot is found
i++;
return i % (SizeArr + 1) - 1; // Return the index of the empty slotDetails:
|