1 / 12

ADTs - Stacks

ADTs - Stacks. By Adam Thomas, Miekah Broomes , Sankara Daly. Objectives. Define a stack. List and explain the operations of a stack. Discuss practical needs of implementing a stack. What is a stack?.

teague
Download Presentation

ADTs - Stacks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ADTs - Stacks By Adam Thomas, MiekahBroomes, Sankara Daly

  2. Objectives • Define a stack. • List and explain the operations of a stack. • Discuss practical needs of implementing a stack.

  3. What is a stack? • A stack is a list of data items that can only be accessed at one end, known as the top of the stack. • It is an ADT (Abstract Data Type), which is a data package which contains both the data structure and the operations that can be performed on this data structure.

  4. Stack Operations • Just like any other data structure, there are operations which can be carried out with Stacks. • The four basic stack operations are: • Stack: Creates an empty stack. • Push: Inserts an element at the top of the stack. • Pop: Deletes the top element. • Empty: Checks the status of the stack.

  5. ‘Stack’ Operation • Before we can do anything with a stack, we must create a stack in the first place. • The stack operation creates an empty stack in memory. It is denoted in the following format. Empty stack stackName

  6. ‘Push’ and ‘Pop’ Operation • The push operation is used to add data into a stack. • The pop operation is used to remove data from a stack. • N.B. Data is always added to/subtracted from the top of the stack.

  7. Animation of Push and Pop Operations Click to begin animation End of animation. Push Pop Stack

  8. Application Stacks • There a four basic application stacks: reversing data, pairing data, postponing data usage and backtracking steps.

  9. Reversing Data • Reversing data items requires that a given set of data items be reordered so that the first and last items are exchanged, with all of the positions between the first and last also being relatively exchanged

  10. Pairing Data • Paring data is any logic that breaks data into independent pieces for further processing. • E.g to translate a source program to machine language

  11. Postponing Data Usage • This is deferring data usage till some later point within the program. E.g manual transformation

  12. Backtracking Steps •  This is a process when you need to access the most recent data element in a series of elements. Think of a labyrinth or maze - how do you find a way from an entrance to an exit? Once you reach a dead end, you must backtrack. But backtrack to where? to the previous choice point. Therefore, at each choice point you store on a stack all possible choices. Then backtracking simply means popping a next choice from the stack.

More Related