SlideShare uma empresa Scribd logo
1 de 20
Lists, Queues, Sta
cks
CST200 – Week 5: Array based Implementation

Instructor: Andreea Molnar
Outline
• Lists
• Queues
• Stacks
List
A sequence of items that has at least the
functionality below:

• Accessing an item at a given position
• Adding an item at a given position
• Removing an item
• Determining the number of items
Stack
A sequence of items in which:

•
•

An item can be inserted only to the top
Only the top item can be
accessed/removed

In a stack items are inserted and removed
according to the last-in first-out (LIFO)
principle.
Stack
Functionality:

•
•
•
•
•

push: insert an item to the top of the stack
pop: remove the item at the top of the stack

peek: get the item at the top of the stack
isEmpty: assess if the stack is empty

isFull: assess if the stack is full
Stack
Assuming that one has an object myStack:

myStack.push (25)

25

myStack
Stack
Assuming that one has an object myStack:

myStack.push (25)
myStack.push (10)

10

25

myStack
Stack
Assuming that one has an object myStack:

myStack.push (25)

myStack.push (10)

10
25

myStack

int topValue = myStack.pop ()

10

topValue
Stack
Assuming that one has an object myStack:
myStack.push (25)
myStack.push (10)

int topValue = myStack.pop ()

5
25

mySta
ck

myStack.push (5)

10

topVa
lue
Stack
Assuming that one has an object myStack
myStack.push (25)
myStack.push (10)

5
25

myStack

int topValue = myStack.pop ()
myStack.push (5)

10

topValue
Stack
Assuming that one has an object myStack:
myStack.push (25)
myStack.push (10)
int topValue = myStack.pop ()
myStack.push (5)
myStack.push (20)

20
5
25
10

myStack

topValue
Stack
Assuming that one has an object myStack:
myStack.push (25)

myStack.push (10)
int topValue = myStack.pop ()

myStack.push (5)
myStack.push (20)
topValue = myStack.pop ()

20
5
25
20

myStack

topValue
Queue
A sequence of items in which the first
element inserted is the first one to be
removed.
In a queue elements are inserted and
removed based on the the first-in first-out
(FIFO) principle.
Queue
Functionality:

•
•
•

enqueue: add an item to the back of the queue

dequeue: remove the front item
getFront: get the front item
Queue
Assuming that one has an object myQueue:

myQueue.enque (25)

25

myQueue
Queue
Assuming that one has an object myQueue:

myQueue.enque (25)
int value = myQueue.deque ()

25

25

myQueue

value
Queue
Assuming that one has an object myQueue:

myQueue.enque (25)
int value = myQueue.deque ()

20

myQueue

myQueue.enque (20)

25

value
Queue
Assuming that one has an object myQueue:

myQueue.enque (25)
int value = myQueue.deque ()

myQueue.enque (20)

20

5

myQueue

myQueue.enque (5)

25

value
Queue
Assuming that one has an object myQueue:
myQueue.enque (25)
int value = myQueue.deque ()
myQueue.enque (20)

20

5

myQueue

myQueue.enque (5)
value = myQueue.deque ()

20

value
Summary
•
•
•

A list is sequence of items that allows to access, add
and remove an arbitrary element and determine the
numbers of items (length/size of the list).
A stack is a data structure in which an item can be
added, accessed or removed only from the top.
A queue is a data structure in which the first element
added is the first one to be accessed/removed.

Mais conteúdo relacionado

Semelhante a Lists, queues and stacks 1

Semelhante a Lists, queues and stacks 1 (20)

Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
QueuYUGHIJLK;KJHGFCFYUGIHOJUHYGHJIOIHGes.ppt
QueuYUGHIJLK;KJHGFCFYUGIHOJUHYGHJIOIHGes.pptQueuYUGHIJLK;KJHGFCFYUGIHOJUHYGHJIOIHGes.ppt
QueuYUGHIJLK;KJHGFCFYUGIHOJUHYGHJIOIHGes.ppt
 
stack coding.pptx
stack coding.pptxstack coding.pptx
stack coding.pptx
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
stack presentation
stack presentationstack presentation
stack presentation
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfCEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Queue
QueueQueue
Queue
 
GAC DS Priority Queue Presentation 2022.ppt
GAC DS Priority Queue Presentation 2022.pptGAC DS Priority Queue Presentation 2022.ppt
GAC DS Priority Queue Presentation 2022.ppt
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
stack in java data structure - muhammed .ppt
stack in java data structure - muhammed .pptstack in java data structure - muhammed .ppt
stack in java data structure - muhammed .ppt
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 

Mais de ASU Online

Midterm common mistakes
Midterm common mistakesMidterm common mistakes
Midterm common mistakesASU Online
 
Classes revision
Classes revisionClasses revision
Classes revisionASU Online
 
For loop java 2
For loop java 2For loop java 2
For loop java 2ASU Online
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2ASU Online
 
Common errors v2
Common errors v2Common errors v2
Common errors v2ASU Online
 
Common missunderestandings
Common missunderestandingsCommon missunderestandings
Common missunderestandingsASU Online
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaASU Online
 
Lecture 14 tourism in europe
Lecture 14   tourism in europeLecture 14   tourism in europe
Lecture 14 tourism in europeASU Online
 
Lecture 13 tourism in the south pacific
Lecture 13   tourism in the south pacificLecture 13   tourism in the south pacific
Lecture 13 tourism in the south pacificASU Online
 
Lecture 12 tourism in australia and new zealand
Lecture 12   tourism in australia and new zealandLecture 12   tourism in australia and new zealand
Lecture 12 tourism in australia and new zealandASU Online
 
Lecture 11 tourism in east asia
Lecture 11   tourism in east asiaLecture 11   tourism in east asia
Lecture 11 tourism in east asiaASU Online
 
Lecture 9 tourism in south asia
Lecture 9   tourism in south asiaLecture 9   tourism in south asia
Lecture 9 tourism in south asiaASU Online
 
Lecture 9 tourism in south asia-1
Lecture 9   tourism in south asia-1Lecture 9   tourism in south asia-1
Lecture 9 tourism in south asia-1ASU Online
 
Lecture 8 tourism in central asia
Lecture 8   tourism in central asiaLecture 8   tourism in central asia
Lecture 8 tourism in central asiaASU Online
 
Lecture 7 tourism in the middle east and north africa
Lecture 7   tourism in the middle east and north africaLecture 7   tourism in the middle east and north africa
Lecture 7 tourism in the middle east and north africaASU Online
 
Lecture 6 tourism in sub-saharan africa
Lecture 6   tourism in sub-saharan africaLecture 6   tourism in sub-saharan africa
Lecture 6 tourism in sub-saharan africaASU Online
 
Lecture 5 tourism in latin america
Lecture 5   tourism in latin americaLecture 5   tourism in latin america
Lecture 5 tourism in latin americaASU Online
 
Lecture 4 tourism in the caribbean
Lecture 4   tourism in the caribbeanLecture 4   tourism in the caribbean
Lecture 4 tourism in the caribbeanASU Online
 
Lecture 3 political context of international tourism
Lecture 3   political context of international tourismLecture 3   political context of international tourism
Lecture 3 political context of international tourismASU Online
 
Lecture 2 impacts of tourism global dist
Lecture 2 impacts of tourism   global distLecture 2 impacts of tourism   global dist
Lecture 2 impacts of tourism global distASU Online
 

Mais de ASU Online (20)

Midterm common mistakes
Midterm common mistakesMidterm common mistakes
Midterm common mistakes
 
Classes revision
Classes revisionClasses revision
Classes revision
 
For loop java 2
For loop java 2For loop java 2
For loop java 2
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2
 
Common errors v2
Common errors v2Common errors v2
Common errors v2
 
Common missunderestandings
Common missunderestandingsCommon missunderestandings
Common missunderestandings
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Lecture 14 tourism in europe
Lecture 14   tourism in europeLecture 14   tourism in europe
Lecture 14 tourism in europe
 
Lecture 13 tourism in the south pacific
Lecture 13   tourism in the south pacificLecture 13   tourism in the south pacific
Lecture 13 tourism in the south pacific
 
Lecture 12 tourism in australia and new zealand
Lecture 12   tourism in australia and new zealandLecture 12   tourism in australia and new zealand
Lecture 12 tourism in australia and new zealand
 
Lecture 11 tourism in east asia
Lecture 11   tourism in east asiaLecture 11   tourism in east asia
Lecture 11 tourism in east asia
 
Lecture 9 tourism in south asia
Lecture 9   tourism in south asiaLecture 9   tourism in south asia
Lecture 9 tourism in south asia
 
Lecture 9 tourism in south asia-1
Lecture 9   tourism in south asia-1Lecture 9   tourism in south asia-1
Lecture 9 tourism in south asia-1
 
Lecture 8 tourism in central asia
Lecture 8   tourism in central asiaLecture 8   tourism in central asia
Lecture 8 tourism in central asia
 
Lecture 7 tourism in the middle east and north africa
Lecture 7   tourism in the middle east and north africaLecture 7   tourism in the middle east and north africa
Lecture 7 tourism in the middle east and north africa
 
Lecture 6 tourism in sub-saharan africa
Lecture 6   tourism in sub-saharan africaLecture 6   tourism in sub-saharan africa
Lecture 6 tourism in sub-saharan africa
 
Lecture 5 tourism in latin america
Lecture 5   tourism in latin americaLecture 5   tourism in latin america
Lecture 5 tourism in latin america
 
Lecture 4 tourism in the caribbean
Lecture 4   tourism in the caribbeanLecture 4   tourism in the caribbean
Lecture 4 tourism in the caribbean
 
Lecture 3 political context of international tourism
Lecture 3   political context of international tourismLecture 3   political context of international tourism
Lecture 3 political context of international tourism
 
Lecture 2 impacts of tourism global dist
Lecture 2 impacts of tourism   global distLecture 2 impacts of tourism   global dist
Lecture 2 impacts of tourism global dist
 

Lists, queues and stacks 1

  • 1. Lists, Queues, Sta cks CST200 – Week 5: Array based Implementation Instructor: Andreea Molnar
  • 3. List A sequence of items that has at least the functionality below: • Accessing an item at a given position • Adding an item at a given position • Removing an item • Determining the number of items
  • 4. Stack A sequence of items in which: • • An item can be inserted only to the top Only the top item can be accessed/removed In a stack items are inserted and removed according to the last-in first-out (LIFO) principle.
  • 5. Stack Functionality: • • • • • push: insert an item to the top of the stack pop: remove the item at the top of the stack peek: get the item at the top of the stack isEmpty: assess if the stack is empty isFull: assess if the stack is full
  • 6. Stack Assuming that one has an object myStack: myStack.push (25) 25 myStack
  • 7. Stack Assuming that one has an object myStack: myStack.push (25) myStack.push (10) 10 25 myStack
  • 8. Stack Assuming that one has an object myStack: myStack.push (25) myStack.push (10) 10 25 myStack int topValue = myStack.pop () 10 topValue
  • 9. Stack Assuming that one has an object myStack: myStack.push (25) myStack.push (10) int topValue = myStack.pop () 5 25 mySta ck myStack.push (5) 10 topVa lue
  • 10. Stack Assuming that one has an object myStack myStack.push (25) myStack.push (10) 5 25 myStack int topValue = myStack.pop () myStack.push (5) 10 topValue
  • 11. Stack Assuming that one has an object myStack: myStack.push (25) myStack.push (10) int topValue = myStack.pop () myStack.push (5) myStack.push (20) 20 5 25 10 myStack topValue
  • 12. Stack Assuming that one has an object myStack: myStack.push (25) myStack.push (10) int topValue = myStack.pop () myStack.push (5) myStack.push (20) topValue = myStack.pop () 20 5 25 20 myStack topValue
  • 13. Queue A sequence of items in which the first element inserted is the first one to be removed. In a queue elements are inserted and removed based on the the first-in first-out (FIFO) principle.
  • 14. Queue Functionality: • • • enqueue: add an item to the back of the queue dequeue: remove the front item getFront: get the front item
  • 15. Queue Assuming that one has an object myQueue: myQueue.enque (25) 25 myQueue
  • 16. Queue Assuming that one has an object myQueue: myQueue.enque (25) int value = myQueue.deque () 25 25 myQueue value
  • 17. Queue Assuming that one has an object myQueue: myQueue.enque (25) int value = myQueue.deque () 20 myQueue myQueue.enque (20) 25 value
  • 18. Queue Assuming that one has an object myQueue: myQueue.enque (25) int value = myQueue.deque () myQueue.enque (20) 20 5 myQueue myQueue.enque (5) 25 value
  • 19. Queue Assuming that one has an object myQueue: myQueue.enque (25) int value = myQueue.deque () myQueue.enque (20) 20 5 myQueue myQueue.enque (5) value = myQueue.deque () 20 value
  • 20. Summary • • • A list is sequence of items that allows to access, add and remove an arbitrary element and determine the numbers of items (length/size of the list). A stack is a data structure in which an item can be added, accessed or removed only from the top. A queue is a data structure in which the first element added is the first one to be accessed/removed.