+ 1
How does pop function work in stack?
In all implementations of stack in c#, what I saw for pop function is something like this, public T pop() { return arr[--index]; } This is really different than how I used to implement stack in c++. As you may know that, in c++ we also free the memory that topmost element occupies with the help of pointers. Actually, not only stack but also other generic arrays like list, queue. Does topmost element still occupy memory in RAM with the function above ( because it seems so, since it is already in the array ) or not? If it is removed from memory then how is it?
1 ответ
+ 1
C# does automatic memory management and garbage collection for you so you don't need to free the memory after you are done with it, simply.