Domanda di colloquio di BlackBerry

Implement Stack with Linked List

Risposta di colloquio

Anonimo

9 giu 2011

Stacks are LIFO. Have a pointer, *last, that will point to the very first element pushed onto the stack (this will never change, it is the last element to be popped). For the push method, create a new element, update the pointer, *first, to point at this new element, while the *next pointer points to the next element on the stack. For the pop method, the *first element points to the next element in the stack.