What would be the algorithm to remove something from an array of things?
you iterate over each item adding each element to a temp array except the element you wish to remove (elementIndex -1) then just make the original reflect the changes of the temp array
what language? do you want it to be returned or just removed? will u replace the spot with a null object or a zero value or something else or just move everything else after one place?
if an element id removed from an array of size 1xN, you get a new array of size 1x(N-1) say we want to remove k^th element step 1) create a new array of size 1x(N-1) step 2) copy all contents from 1 to (k-1 ) from original array to the new array step 3) copy all contents from (k+1) to N from original array to the new array the new array is now the original array without the k^th element.
correct me if i am wrong. arrays are not re-sizable so if u delete/ remove an item from it u get a null object at its place. so or as @electrokid says u "play" with 2 arrays , or u use something else that is re-sizable. ex. ArrayList or something else.
yeah I know you have to use two arrays. With arraylists its easier because they have a remove method.
in object oriented programming, using classes, like "vector class" in C++, you can modify the array.
i believe this is java though..or am i wrong?
yes its java
but you can do this in other languages too
@akhaliq99 I see you are creating a doxygen manual for this ;)
ofc u can :)
right I think its called javadoc in java
it does in the first for loop
saw that
why do you need two loops though.. you can do the same in one loop
sounds about right then
Join our real-time social learning platform and learn together with your friends!