15,942,964 members
See more:
Algorithm to delete the value at location K of an array "Country" having N elements

1. Input location K

2. Input K>N then

Print invalid location
Return
END IF

[move each element from the specified location on step towards the beginning.The item at the specified location is automatically deleted]

3.Repeat For C=K To N-1
Country[C]=Country[C+1];
[End of loop]

4.Exit

i want to ask if my arraysize is Country[5] and index is form 0 to n-1. if i want to delete the element at last index 4 then what this algorithm do? How it works?
Posted
Lakamraju Raghuram 26-Jan-12 9:19am
Is this not similar to your earlier question?
Is this some sort of test/homework given to you?
ALIWAZ 26-Jan-12 9:40am
no sir a small confusion in my mind about last index in case of arraysize is static

## Solution 1

Assuming that your pseudo code 1) operates an exclusive test and 2) that there is an implicit increment by one involved; i.e. the values of C increase by one each time round the loop provided that the value after increment is less than but not equal to (N-1):
```N = 5.
K = 0
C = {0, 1, 2, 3}```
It would do nothing.

If either of these condition is not true, then it will fail, either because it will exceed the array limits, or it will never exit the loop.

Espen Harlinn 26-Jan-12 10:19am
5'ed! :)

## Solution 2

This is (basically) the same issue as you asked here[^]. Why not take the advice given and use a proper dynamic container class and forget about using static arrays, which will only cause you unnecessary pain.