Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
removeCDAback
#1
It says:
"

  • removeCDAfront - The size shall be greater than zero. 

  • removeCDAback - The size shall be greater than zero. 
"
So size mean how many item in the array.
Capacity mean the maximum number of items array can hold.

So my test output was like:


---remove-B----head---------------: 0.
---remove-B------------------tail---------------: 2.
---remove-B--Array size: 3.
---remove-B--Array capacity: 8.


*************capacity shrink to : 4


---remove-B----head---------------: 0.
---remove-B------------------tail---------------: 1.
---remove-B--Array size: 2.
---remove-B--Array capacity: 4.


*************capacity shrink to : 2


---remove-B----head---------------: 0.
---remove-B------------------tail---------------: 0.
---remove-B--Array size: 1.
---remove-B--Array capacity: 2.
Size was 1, can't remove.
Size was 1, can't remove.
Size was 1, can't remove.
Size was 1, can't remove.
(97)(1)



So I set two if statement for when size was one and capacity was one just return the last item and do not remove it.
Because it said size should be greater than zero which means minimum was one.

Was that correct?

Or the size can be zero, and array can be empty by remove function?
Reply
#2
Yes, the remove method can take the last item out of the array.

It is an error to try to remove something from an empty array.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)