Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stack Implementations

Similar presentations


Presentation on theme: "Stack Implementations"— Presentation transcript:

1 Stack Implementations
Chapter 6 Adapted from Pearson Education, Inc.

2 Contents A Linked Implementation An Array-Based Implementation
A Vector-Based Implementation Java Class Library: The Class Vector Using a Vector to Implement the ADT Stack Adapted from Pearson Education, Inc.

3 Objectives Implement ADT stack by using either
Linked chain Array Vector Compare and contrast various implementations and their performance Adapted from Pearson Education, Inc.

4 Stack operations Consider peek Consider push Another push Consider pop
Farah Manal Samia Samia Asma Adapted from Pearson Education, Inc.

5 Stack operations Consider peek Consider push Another push Consider pop
Which end of the stack is involved? The TOP Samia Farah Manal Samia Asma Adapted from Pearson Education, Inc.

6 Linked Implementation
Which is better? Why? The TOP Samia Farah Manal Samia Asma FirstNode Manal Samia Asma FirstNode Manal Samia Asma Adapted from Pearson Education, Inc.

7 Linked Implementation
null; return { top = topNode.data; topNode = topNode.next; } null; Adapted from Pearson Education, Inc.

8 Linked Implementation
null; { T top = topNode.data; topNode = topNode.next; return top; } return null; } { top = topNode.data; topNode = topNode.next; } Adapted from Pearson Education, Inc.

9 Array Implementation Which is better? Why? Samia Farah Manal Samia
The TOP Samia Farah Manal Samia Asma Top Asma Samia Manal 2 Top 1 2 3 4 1 2 3 4 Manal Samia Asma Adapted from Pearson Education, Inc.

10 Adding to the Top Adapted from Pearson Education, Inc.

11 Peek and Pop Adapted from Pearson Education, Inc.

12 End Chapter 6 Adapted from Pearson Education, Inc.


Download ppt "Stack Implementations"

Similar presentations


Ads by Google