CS261 Data Structures Bags, Queues and Stacks Bag Problem : Need - - PowerPoint PPT Presentation

cs261 data structures
SMART_READER_LITE
LIVE PREVIEW

CS261 Data Structures Bags, Queues and Stacks Bag Problem : Need - - PowerPoint PPT Presentation

CS261 Data Structures Bags, Queues and Stacks Bag Problem : Need to maintain an unordered collection of elements Operations : Insert Remove Contains Specific requirements : E.g., Time of insertion into bag is important


slide-1
SLIDE 1

CS261 Data Structures

Bags, Queues and Stacks

slide-2
SLIDE 2

Bag

  • Problem: Need to maintain an unordered

collection of elements

  • Operations:

– Insert – Remove – Contains

  • Specific requirements:

– E.g., Time of insertion into bag is important

slide-3
SLIDE 3

Bag Interface

  • Provide functions for operations

addBag (container, value) testBag (container, value) removeBag (container, value) sizeBag (container, value)

slide-4
SLIDE 4

Queue

  • Problem: Maintain a collection of elements in

First-In, First-Out format

  • Operations:

– Add an element to Queue – Remove an element from Queue – Read the front element of Queue – Contains

slide-5
SLIDE 5

Stack

  • Problem: Maintain a collection of elements in

Last-In, First-Out format

  • Operations:

– Add an element to Stack – Remove an element from Stack – Read the top element of Stack – Contains

slide-6
SLIDE 6

Difference between ADT and Implementation

  • Stack ADT

– Can be implemented using dynamic array – Linked list – …

  • Encapsulation idea

– User don’t care what’s implemented – Just tell user how fast is each operation