SYSC 2006 Lecture Notes - Lecture 21: Linked List, C Dynamic Memory Allocation, In C
Document Summary
A stack is a collection in which elements are maintained in the order in which they are added. They differ from queues as stacks are lifo collections (last - in, first - out) Determine the length (size) of a stack (i. e. , # of elements) Print the contents of a stack - useful for testing/ debugging. Iterate over the contents of a stack - useful for testing/ debugging. In general, a stack should not provide support to the following operations as they contradict the stack"s. Lifo protocol search a stack for a specific element remove a specific element from a stack retrieve/ replace/ insert/ delete/ an element at a specific position in the stack. In c, we can use an array or singly linked list as a data structure that permits efficient implementation of a stack. In python, a stack is implemented using the list class. In java, a stack is implemented using the arraylist class.