Presentation is loading. Please wait.

Presentation is loading. Please wait.

Container classes, ADTs

Similar presentations


Presentation on theme: "Container classes, ADTs"— Presentation transcript:

1 Container classes, ADTs
stack and queue are “standard” data structures implemented in STL, 100/100e/108 versions too templated classes, can hold any kind of object stack is a LIFO structure, queue is FIFO When is each appropriate? What are differences? Queue as an ADT create, enqueue, dequeue, front, isEmpty stack analogs: create, push, pop, top, isEmpty

2 Applications/Implementations
printing, job scheduling discrete event simulations why simulate rather than build? Burger king vs McDonalds, what’s the difference? How are stacks/queues implemented? using vectors or linked lists, pros/cons? Stack using vector, where to push/pop? Queue as circular linked list, where to enqueue/dequeue?

3 Circular linked list Where is the front? Node declaration:
template <class Type> struct Node { Type info; Node * next; Node (const Type & val, Node * link=0) : info(val), next(link) {} }; Node<string> * s = new Node<string>(“apple”); Node<int> * n = new Node<int>(3); what about default constructor? “apple” “pear” “kiwi” “guava” “lime” Where is the front?

4 What is a templated class?
Not code, but a code generator when template is instantiated, code is generated Vector<int> vi(100); creates an int vector Vector<string> vs(100); creates a string vector templated classes (and functions) are generic template parameter is used to instantiate class template <class Type> class Stack{… template <class Type> class Queue{… Queue<string> q; Stack<int> s;


Download ppt "Container classes, ADTs"

Similar presentations


Ads by Google