Skip to main content
ICT
Lesson AB31 - Stacks and Queues
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

A. Stacks page 3 of 10

  1. A stack is a linear data structure.

  2. All additions to and deletions from a stack occur at the top of the stack. The last item pushed onto the stack will be the first item removed. A stack is sometimes referred to as a LIFO ('Last-In, First-Out') structure.

  3. Two of the more important stack operations involve pushing data onto a stack and popping data off the stack.

  4. Diagram 31-1 (below) illustrates the push operation:


    Diagram 31-1: Push Operation

  5. Diagram 31-2 illustrates the pop operation:

  6. Diagram 31-2: Pop Operation

  7. Stacks are very useful for implementing recursion. The local values of a method are placed on a stack each time the method calls itself. When the method returns, the stack is popped to restore the local values for that call. Another example of using a stack structure is when a web browser stores the URLs that are visited. When a new URL is visited it is placed on a stack. When the back button is used, the stack is popped.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.