Hi,
Regarding the pop() implementation mentioned in the course:
Lets say their is only 1 element in the stack (so as in the array), when I call pop() on the stack the implementation returns the element pointed by “top” variable and decrements it.
Statement is:
return array[top–];
but this only changes the value of the “top” variable by setting it to -1(from 0) and never removes the element from the array.
But, when I verified this by printing the backed array, the element at index 0 was set to value 0.
How come it deletes the value in the backed array? (as there is no replacement logic anywhere)
Thank you.
Regards,
Puneeth