Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

What would be the algorithm to remove something from an array of things?

OpenStudy (anonymous):

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

OpenStudy (microbot):

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?

OpenStudy (anonymous):

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.

OpenStudy (microbot):

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.

OpenStudy (anonymous):

yeah I know you have to use two arrays. With arraylists its easier because they have a remove method.

OpenStudy (anonymous):

in object oriented programming, using classes, like "vector class" in C++, you can modify the array.

OpenStudy (microbot):

i believe this is java though..or am i wrong?

OpenStudy (anonymous):

yes its java

OpenStudy (anonymous):

but you can do this in other languages too

OpenStudy (anonymous):

@akhaliq99 I see you are creating a doxygen manual for this ;)

OpenStudy (microbot):

ofc u can :)

OpenStudy (anonymous):

right I think its called javadoc in java

OpenStudy (anonymous):

it does in the first for loop

OpenStudy (anonymous):

saw that

OpenStudy (anonymous):

why do you need two loops though.. you can do the same in one loop

OpenStudy (anonymous):

sounds about right then

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!