int main(){ PriorityQueue<int> pq; std::cout << pq.size() << std::endl; pq.enqueue(1); pq.present(); pq.enqueue(5); pq.present(); pq.enqueue(9); pq.present(); std::cout << pq.size() << " - " << pq.peek() << std::endl; pq.enqueue(7); pq.present(); pq.enqueue(3); pq.present(); pq.enqueue(0); pq.enqueue(10); pq.present(); std::cout << pq.size() << " - " << pq.peek() << std::endl; pq.dequeue(); pq.present(); pq.dequeue(); pq.present(); std::cout << pq.size() << " - " << pq.peek() << std::endl; return 0; }
/* main() manages the user interface; * instantiates priority queue object, then operates loop to read input * from user and call the appropriate priority queue method */ int main() { PriorityQueue pq; TokenScanner scanner; while (true) { string line = getLine("> "); scanner.setInput(line); scanner.ignoreWhitespace(); string cmd=scanner.nextToken(); if (cmd == "help") { helpCommand(); } else if (cmd == "enqueue") { if(scanner.hasMoreTokens()){ string value=scanner.nextToken(); if(scanner.hasMoreTokens()){ scanner.scanNumbers(); string priorityStr=scanner.nextToken(); double priority=stringToDouble(priorityStr); pq.enqueue(value,priority); } else pq.enqueue(value); } } else if (cmd == "dequeue") { if(pq.isEmpty()) cout<<"The queue is empty"<<endl; else cout<<pq.dequeue()<<endl; } else if (cmd == "peek") { if(pq.isEmpty()) cout<<"The queue is empty"<<endl; else cout<<pq.peek()<<endl; } else if (cmd == "peekPriority"||cmd=="peekpriority") { if(pq.isEmpty()) cout<<"The queue is empty"<<endl; else cout<<pq.peekPriority()<<endl; } else if (cmd == "clear") { pq.clear(); } else if (cmd == "size") { cout<<pq.size()<<endl; } else if (cmd == "isEmpty"||cmd=="isempty") { if(pq.isEmpty()) cout<<"true"; else cout<<"false"; cout<<endl; } else if(cmd=="list") list(pq); else { cout << "Undefined command: " << cmd << endl; } } return 0; }