{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

4_stacks_queue - Data Structures Example Sorting elements...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 4 Mar 17 2004 Data Structures * S of numbers S in increasing order S S S ≠ ∅ Key to a good solution: data structure for S Topics for next 5 lectures •Today: –Stacks and Queues –FIFO vs. LIFO –Implementations using arrays –Expression Conversion Stacks and Queues removed from the set by the Delete operation is prespecified. most recently inserted element element that has been in the set the longest Example: Sorting elements Input: a set Output: elements of Algorithm: 1. Locate smallest item in 2. Output smallest item 3. Delete smallest item from 4. GOTO 1, while • Elementary data structures – Stacks and Queues – Linked lists – Graphs – Trees • Dynamic sets in which the element • STACK – Element deleted is: • QUEUE – Element deleted is:
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Stack Stack : A list with insertion and deletion both take place at one end: the top Main operations Push by one Pop one Other operations LIFO policy addition makes older items inaccessible Stack Implementing Stack using Array 5 3 12 0 42 S 8 Top[S]=6 5 3 12 0 42 17 2 S 8 Top[S]=8 5 3 12 0 42 17 2 S 8 Top[S]=7 Empty( S ) if top [ S ]=1 then
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}