4_stacks_queue

4_stacks_queue - Introduction to Computers and Programming...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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: 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 return true else return false New item added on top of stack, size of stack increases...
View Full Document

This note was uploaded on 01/28/2012 for the course AERO 16.01 taught by Professor Markdrela during the Fall '05 term at MIT.

Page1 / 6

4_stacks_queue - Introduction to Computers and Programming...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online