Page 142 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 142

Unit 9: Stacks




                                                                                                Notes
                                    Figure 9.3: Shipment in a Cargo









          Source: http://www.tup.tsinghua.edu.cn/Resource/tsyz/034111-01.pdf
          Figure 9.4 shows the schematic diagram of a stack.

                                Figure 9.4: Schematic Diagram of a Stack


















          Source:  http://www.tup.tsinghua.edu.cn/Resource/tsyz/034111-01.pdf
          Other names for a stack are pushdown list, and LIFO (or) Last In First Out list. The stack allows
          access to only one item, i.e. the last item inserted. In the schematic diagram of a stack, after
          inserting Item 4 into the stack, it acts as the topmost element. It will be removed first. The very
          first item that was inserted into the stack is Item 1. It will be removed as the last item.

          Self Assessment

          Fill in the blanks:
          1.   A ....................... is an ordered collection of homogeneous data elements where the insertion
               and deletion operations occur at one end only, called the top of the stack.
          2.   The stack allows access to only one item, i.e. the last item inserted. This is also known as
               ....................... system.

          9.2 Operations on Stacks


          The primitive operations that can be performed on a stack are given below:
          1.   Inserting an element into the stack (PUSH operation)
          2.   Removing an element from the stack (POP operation)
          3.   Determining the top item of a stack without removing it from the stack (PEEP operation)

          PUSH operation is used to insert the data elements in a stack. The push operation inserts an
          element on to a stack and the element inserted settles down on the stack. Practically saying, a
          stack can be an array where elements are inserted in LIFO fashion.




                                           LOVELY PROFESSIONAL UNIVERSITY                                   135
   137   138   139   140   141   142   143   144   145   146   147