Sessions 26 and 27 - Data Structures & Algorithm

1 the list is 22 11 the list is 33 22 11 sharif

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: g: Sessions 26 and 27: Data Structures & Algorithm 43 45 46 47 48 49 50 51 52 53 53 54 55 56 57 // pop floating-point values from doubleStack double popDouble; while ( !doubleStack.isStackEmpty() ) { doubleStack.pop( popDouble ); cout << popDouble << " popped from stack" << endl; doubleStack.printStack(); } // end while return 0; } // end main Sharif University of Technology Introduction to Programming: Sessions 26 and 27: Data Structures & Algorithm 44 processing an integer Stack The list is: 0 The list is: 1 0 The list is: 2 1 0 The list is: 3 2 1 0 3 popped from stack The list is: 2 1 0 2 popped from stack The list is: 1 0 1 popped from stack The list is: 0 0 popped from stack The list is empty processing a double Stack The list is: 1.1 The list is: 2.2 1.1 The list is: 3.3 2.2 1.1 Sharif University of Technology Introduction to Programming: Sessions 26 and 27: Data Structures & Algorithm 45 The list is: 4.4 3.3 2.2 1.1 4.4 popped from stack The list is: 3.3 2.2 1.1 3.3 popped from stack The list is: 2.2 1.1 2.2 popped from stack The list is: 1.1 1.1 popped from stack The list is empty All nodes destroyed All nodes destroyed Sharif University of Technology Introduction to Programming: Sessions 26 and 27: Data Structures & Algorithm 46 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 // Template Stack class definition with composed List object. #ifndef STACKCOMPOSITION #define STACKCOMPOSITION #include "list.h" // List class definition template< class STACKTYPE > class Stack { Alternative implementation of stack.h, using composition. public: // no constructor; List constructor does initialization // push calls stackList object's insertAtFront function void push( const STACKTYPE &data ) { stackList.insertAtFront( data ); Declare a private List member, use to manipulate stack. } // end function push // pop calls stackList object's removeFromFront function bool pop( STACKTYPE &data ) { return stackList.removeFromFront( data ); } // end function pop Sharif University of Technology Introduction to Programming: Sessions 26 and 27: Data Structures & Algorithm 47 28 29 30 31 32 33 34 35 36 37 38 39 40 40 41 42 43 44 45 46 47 // isStackEmpty calls stackList object's isEmpty function bool isStackEmpty() const { return stackList.isEmpty(); } // end function isStackEmpty // printStack calls stackList object's print function void printStack() const { stackList.print(); } // end function printStack private: List< STACKTYPE > stackList; // composed List object }; // end class Stack #endif Sharif University of Technology Introduction to Programming: Sessions 26 and 27: Data Structures & Algorithm 48 Queues Queue Like waiting in line Nodes added to back (tail), removed from front (head) First-in, first-out (FIFO) data structure Insert/remove called enqueue/dequeue Applications Print spooling Documents wait in queue until printer available Packets on network File requests from server Sharif...
View Full Document

This note was uploaded on 09/01/2013 for the course CE CE230 taught by Professor Arash during the Fall '13 term at Sharif University of Technology.

Ask a homework question - tutors are online