cs261 data structures
play

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


  1. CS261 Data Structures Bags, Queues and Stacks

  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

  3. Bag Interface • Provide functions for operations addBag (container, value) testBag (container, value) removeBag (container, value) sizeBag (container, value)

  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

  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

  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

Recommend


More recommend