Given an array of like
I don't see how to find the and remove the 5th element in the worst case, the time is 0(log n).Code:int a[5]= {"2", "4", "5", "8", "11"};
Can someone either explain or point me in the right direction here?
This is a discussion on Possible off topic question about arrays within the C Programming forums, part of the General Programming Boards category; Given an array of like Code: int a[5]= {"2", "4", "5", "8", "11"}; I don't see how to find the ...
Given an array of like
I don't see how to find the and remove the 5th element in the worst case, the time is 0(log n).Code:int a[5]= {"2", "4", "5", "8", "11"};
Can someone either explain or point me in the right direction here?
I don't think you meant to have the quotes around the values.
Also, you can't remove elements from C arrays, since they're fixed size. What exactly do you want to do?
The common way to simulate the "removal" of an element is to shift everything right of it one place left, using memmove or a loop.
The quotes where were a typo. The question stems from an old comphensive exam question given at UC-Berkeley.
Well, to find the fifth element is O(1), because it's an array, so you can just go a[4] and there's the fifth element.
And, as I explained above, you cannot remove an element from a C array, the concept doesn't exist, but you could move everything above down one. However in your example the fifth element is also the last, so that's a bit confusing too.