9Queue_Spring_2016.pdf

9Queue_Spring_2016.pdf - Abstract Data Types Abstract Data...

This preview shows page 1 - 9 out of 28 pages.

CS2134 Abstract Data Types –Abstract Data Types • Abstract description of the operations provided and the relationships among them Different implementations are possible for the same ADT • Separation of concerns between data type implementation and use • Were designed around common algorithmic constructs, rather than physical design –Classes in Object Oriented languages group data (member variables) with operations to manipulate the data (member functions) –OO languages developed to support ADTs
Image of page 1

Subscribe to view the full document.

CS2134 ADT’s stack, queue, priority queue 2 top() push(x) pop() queue front() enqueue/ push(x) dequeue/ pop() back() Priority queue insert(x)/ push(x) top() delete/ pop() VIP service FIFO LIFO stack
Image of page 2
Queue
Image of page 3

Subscribe to view the full document.

CS2134 ADT Queue • FIFO : first in first out • useful whenever there is contention for a resource and “jobs” have to wait –packets in a router –files waiting to be printed –calls to a large company are placed in a queue when the operators are busy • Simulation of “real world” queues: –customers in a store, bank, etc –airplanes waiting for a runway Joe Bob Ann customersInLine clerk 1 clerk 2
Image of page 4
CS2134 There are many possible ways to implement the ADT queue #include <queue> int main () { queue < string > customersInLine; customersInLine. push ( "Joe" ); customersInLine. push ( "Bob" ); customersInLine.push(" Ann "); cout << "# customers waiting is " << customersInLine. size ()<<endl; cout << "Next customer: " << customersInLine. front ()<<endl; 5 Queue Joe Bob Ann customersInLine customersInLine. pop (); cout << "# customers waiting " << customersInLine. size ()<<endl; cout << "Next customer: " << customersInLine. front ()<<endl; customersInLine. pop (); customersInLine.push("Adam"); customersInLine. pop (); customersInLine. pop ();
Image of page 5

Subscribe to view the full document.

Queue Interface: NOT a complete class! template< class Object > class Queue { private: …. public: Queue( ); bool empty ( ) const; const Object& front ( )const; const Object& back ( )const; void push ( const Object& x ); // should be enqueue void push ( Object && x); // should be enqueue void pop ( ); // should be dequeue };
Image of page 6
How to Implement a Queue? Requirement: Constant Time Operations empty queue front a back front b a back
Image of page 7

Subscribe to view the full document.

Thinking about ADT queue a b c F00A F028 F000 EF00 EF00 enqueue(a) enqueue(b) enqueue(c) dequeue() dequeue() dequeue()
Image of page 8
ADT Conceptual Representation Singly Linked List Static Array Dynamic Array & front front empty queue a b a theBack theFront a theBack theFront b a theBack
Image of page 9
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern