1 / 9

Other Linear Structures

Other Linear Structures. Stacks, Queues and Deques. Stacks. The stack is a list-like structure in which elements may be inserted or removed from only one end. A stack follows a LIFO access pattern Elements are stored and removed in reverse order of their arrival

denis
Télécharger la présentation

Other Linear Structures

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. Other Linear Structures Stacks, Queues and Deques

  2. Stacks • The stack is a list-like structure in which elements may be inserted or removed from only one end. • A stack follows a LIFO access pattern • Elements are stored and removed in reverse order of their arrival • Elements are pushed on the stack • Elements are popped off the stack

  3. Useful Operations • Clear • isEmpty • Push • Pop • TopEl • Returns the topmost element without removing it from the stack

  4. What are stacks good for? • Stacks can be used for a lot of activities • Compilers will use them to check for balanced brackets, parenthesis, comment, etc. • You can use them to implement an infinite precision calculator • And of course, the run-time stack

  5. Queues • The queue is a list-like structure that provides restricted access to its elements • Elements are enqueued at the back • Elements are dequed from the front • Queues follow a FIFO access pattern

  6. Useful Operations • Clear • isEmpty • Enqueue • Dequeue • firstEl • Returns the first element without removing it from the queue

  7. What are queues good for? • Queues can be used in many situations • You can use them to determine if a poem is an acrostic • Queuing theory from mathematics obviously will use queues • A bank wants to determine the number of tellers required to keep customer wait to a minimum

  8. Queue Implementation • What are some obvious ways to implement a queue? • Linked • Array based • What is the problem with an array based implementation? • The head and the tail will creep. • What is the solution? • Make the queue circular

  9. Deque • A double ended queue. • You have direct access to both ends of the list. • The STL has an interesting implementation of a deque

More Related