Resizeing an Array
If I have declared of an array (ex. int a[5]) is there any method by which
I could change the length of a[ ] (say to 3)? ie, I need the value of the
a.length to be decreased to 50.
Please tell me the solution in any language which I have tagged.
I would also like to as one more part. if the array a[ ] is created
dynamically and I have entered 100 elements to it. Later I need to modify
the same array, by deleteing the last 50 elements. Now the array should
have only 50 elements and the code a.length should return value 50. How
can I achieve this? NOTE: I do not want to use a third variable or copy
the contents to another array. This is to avoid wasting of memory.
No comments:
Post a Comment