Lists, queues and stacks
Upcoming SlideShare
Loading in...5
×
 

Lists, queues and stacks

on

  • 698 views

 

Statistics

Views

Total Views
698
Views on SlideShare
690
Embed Views
8

Actions

Likes
0
Downloads
10
Comments
0

1 Embed 8

http://vizedhtmlcontent.next.ecollege.com 8

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Lists, queues and stacks Lists, queues and stacks Presentation Transcript

  • Lists, Queues, Stacks 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 mySta ck
  • Stack Assuming that one has an object myStack: myStack.push (25) myStack.push (10) 10 25 mySta ck
  • Stack Assuming that one has an object myStack: myStack.push (25) myStack.push (10) 10 25 mySta ck int topValue = myStack.pop () 10 topVa lue
  • 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 mySta ck int topValue = myStack.pop () myStack.push (5) 10 topVa lue
  • 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 mySta ck topVa lue
  • 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 mySta ck topVa lue
  • 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 myQue ue
  • Queue Assuming that one has an object myQueue: myQueue.enque (25) int value = myQueue.deque () 25 25 myQue ue value
  • Queue Assuming that one has an object myQueue: myQueue.enque (25) int value = myQueue.deque () 20 myQueue.enque (20) 25 myQue ue value
  • Queue Assuming that one has an object myQueue: myQueue.enque (25) int value = myQueue.deque () myQueue.enque (20) 20 5 myQue ue 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.enque (5) value = myQueue.deque () 20 myQue ue 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.