(array) deletion from the end

Can you please help me, give me a simple example of deletion from the end here is the algorithm

1. If n=0 then array is underflow step
2. A (UB) <------- null
UB <---- UB1
3. Stop

Example:
Suppose array
Arr[0]=5 , Arr[1]=8 , Arr[2]=10 , Arr[3]=7


After Deletion
Arr[0]=5 , Arr[1]=8 , Arr[2]=10


How to delete the lest element of array?
Last edited on
How many elements are there in this array?

    { 5, 8, 10, 7 }

And how many in this one?

    { 5, 8, 10 }

Remember, the number of elements available in an array is not the same as the number of elements used in the array.

Hope this helps.
You delete it by not using it. Allocate the array using the maximum possible length, and use a variable that stores the length. Then use that length variable in all your code so it can support different sizes:

1
2
3
4
5
6
7
8
9
10
11
int array[25];
int array_length = 25;
int i;

// array length changes here
array_length = 10;

for(i = 0; i < array_length; i++)
{
  do_something_with(array[i]);
}

Topic archived. No new replies allowed.