COP3502_20_Stacks2

COP3502_20_Stacks2 - Stacks: Implementation in C Computer...

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

View Full Document Right Arrow Icon
Computer Science Department University of Central Florida Stacks: Implementation in C COP 3502 – Computer Science I
Background image of page 1

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

View Full DocumentRight Arrow Icon
Stacks: Implementation in C page 2 Stacks – An Overview Stacks: Stacks are an Abstract Data Type They are NOT built into C We must define them and their behaviors So what is a stack? A data structure that stores information in the form of a stack. Consists of a variable number of homogeneous elements i.e. elements of the same type
Background image of page 2
Stacks: Implementation in C page 3 Stacks – An Overview Stacks: Access Policy: The access policy for a stack is simple: the first element to be removed from the stack is the last element that was placed onto the stack The main idea is that the last item placed on to the stack is the first item removed from the stack Known as the “Last in, First out” access policy LIFO for short The classical example of a stack is cafeteria trays. New, clean trays are added to the top of the stack. and trays are also taken from the top So the last tray in is the first tray taken out
Background image of page 3

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

View Full DocumentRight Arrow Icon
Stacks: Implementation in C page 4 Stacks – An Overview Stacks: Basic Operations: PUSH: This PUSHes an item on top of the stack POP: This POPs off the top item in the stack and returns it Other important tidbit: The end of the stack, where PUSHes and POPs occur, is usually referred to as the TOP of the stack
Background image of page 4
Stacks: Implementation in C page 5 Stacks – An Overview Stacks: Basic Operations: PUSH: This PUSHes an item on top of the stack POP: This POPs off the top item in the stack and returns it Other important tidbit: The end of the stack, where PUSHes and POPs occur, is usually referred to as the TOP of the stack
Background image of page 5

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

View Full DocumentRight Arrow Icon
Stacks: Implementation in C page 6 Stacks – An Overview Stacks: Other useful operations: empty: Typically implemented as a boolean function Returns TRUE if no items are in the stacck full: Returns TRUE if no more items can be added to the stack In theory, a stack should NEVER become full Actual implementations do have limits on the number of elements a stack can store top: Simply returns the value at the top of the stack without actually popping the stack.
Background image of page 6
Stacks: Implementation in C page 7 Stacks: Implementation in C Implementation of Stacks in C: As discussed on the previous lecture, there are two obvious was to implement stacks: 1) Using arrays 2) Using linked lists We will go over both…
Background image of page 7

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

View Full DocumentRight Arrow Icon
Stacks: Implementation in C page 8 Stacks: Implementation in C Array Implementation of Stacks: What components will we need to store? 1)
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 37

COP3502_20_Stacks2 - Stacks: Implementation in C Computer...

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

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