06-Stacks - Chapter 7 Stacks and Queues Chapter 7 Stacks...

Info iconThis preview shows pages 1–6. 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

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

View Full DocumentRight 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: Chapter 7: Stacks and Queues Chapter 7: Stacks and Queues This material is based on contents the book: “Data structures, Algorithms, and Software Principles in C”, from T.A. Standish. Parts also under permission from David McCaughan, University of Guelph, Canada. USF – COP4530 – Data Structures Summer 2009 1 of¡18 a d cCaug a , U e s ty o Gue p , Ca ada Background on stacks Background on stacks • Fast definition: pile of objects – Pushing an object: Adding a new object to the top of stack – Popping an object: Removing of an object from the top • How items are pushed – Top remains on same place – New objects push previous inserted objects down. Top will point to last top pushed object always • How implementations do it – Objects remain in same place – Top pointer is moved up push-down USF – COP4530 – Data Structures Summer 2009 2 of¡18 stack Background on stacks Background on stacks • Using stacks for syntax analyzers – Used by automaton that serve as recognizers – Compilers use stacks to recognize structure of computers programs during execution • Using stacks to hold postponed obligations – Can be called a stack of activation records – Keeps track of a sequence of function calls during program execution – Each time there is a function call, a record for the call is pushed on a stack • LIFO vs FIFO – Stacks are sometimes called LIFO lists (Last In First Out) USF – COP4530 – Data Structures Summer 2009 – Queues are sometimes called LIFO lists (First In First Out) 3 of¡18 Background on stacks Background on stacks • Exercise If you have two stacks, S 1 and S 2 , and a single array A[0:n-1] to use for holding the stack items for both stacks, How could you arrange to represent S 1 and S 2 so that they ach have the greatest possible room for growth before no each have the greatest possible room for growth before no more space remains inside A[0:n-1]? USF – COP4530 – Data Structures Summer 2009 4 of¡18 ADTs for stacks and queues ADTs for stacks and queues • Internal representation of stacks an queues – Can be lists, arrays, etc • Abstract representation • Sequences – Is an ordered arrangement of finitely many components – The length of a sequence is number of components in it • Appearance of elements in sequence hey follow an specific order They follow an specific order – Occurrences of elements may be repeated USF – COP4530 – Data Structures Summer 2009 5 of¡18 ADTs Operations...
View Full Document

This note was uploaded on 12/28/2009 for the course COP COP 4350 taught by Professor Jimeno during the Summer '09 term at University of South Florida.

Page1 / 18

06-Stacks - Chapter 7 Stacks and Queues Chapter 7 Stacks...

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

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