stacks and queues linear lists in which insertionsdeletionsand accesses to values occur almost always at the first or the last node are very frequently encounteredand we give them special names -"the art of computer programmingvolume , knuth stacks support last-infirst-out semantics for inserts and deleteswhereas queues are first-infirst-out stacks and queues are usually building blocks in solution to complex problem as we will soon seethey can also make for stand-alone problems stacks stack supports two basic operations--push and pop elements are added (pushedand removed (poppedin last-infirst-out orderas shown in figure if the stack is emptypop typically returns null or throws an exception when the stack is implemented using linked list these operations have ( time complexity if it is implemented using an arraythere is maximum number of entries it can have--push and pop are still ( if the array is dynamically resizedthe amortized time for both push and pop is ( stack can support additional operations such as peekwhich returns the top of the stack without popping it pop push (ainitial configuration (bpopping ( (cpushing on to (bfigure operations on stack stacks boot camp the last-infirst-out semantics of stack make it very useful for creating reverse iterators for sequences which are stored in way that would make it difficult or impossible to step back from given element this program uses stack to print the entries of singly-linked list in reverse order