Click here to Skip to main content
15,942,964 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

[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
[End of loop]


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?
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

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.
Share this answer
Espen Harlinn 26-Jan-12 10:19am    
5'ed! :)
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.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900