// Native_Queues.cpp : Defines the entry point for the console application. /* _______________________________________________________ W O R K I N G W I T H Q U E U E S A N D D E Q U E S Ron Kessler Created 1/27/2017 Native Code Version Run with CTL-F5 A queue is like a line at the bank or Starbucks. First in, first served. A deque is a similar container but it allows us to iterate over it and it lets you add items to the beginning or end. */ #include "stdafx.h" #include #include #include #include using namespace std; void showCustomersInLine (); //framework for helper function queue names; // Declare a queue deque moreNames; // Declare a deque int main() { names.push ("Ben"); // Add some values to the queue names.push ("Erin"); // Much like vectors names.push ("Dan"); names.push ("Cindy"); names.push ("Karen"); names.push ("Gabriel"); names.push ("Palo"); names.push ("Lucy"); names.push ("Dale"); names.push ("Herman"); cout << "Welcome to Ron's Cookie Store!" << endl << endl; cout << "Here are the customers who are in line...." << endl << endl; cout << "Now serving: " << names.front () << endl << endl; //---get the next customer in line names.pop (); cout << "There are currently " << names.size () << " people in line. " << "The next person in the queue is " << names.front () << ".\n\n" << names.back () << " is the last person in the queue." << endl; cin.get (); system ("cls"); cout << "Now let's look at deque (double-ended queue) which allows us to iterate over it.\n\n"; //---deque can grow in either direction //---use this to give higher priority to someone or some job like a print job! moreNames.push_back ("Ben"); // Add some values to the queue moreNames.push_back ("Erin"); // Much like vectors moreNames.push_back ("Dan"); moreNames.push_back ("Cindy"); moreNames.push_back ("Karen"); moreNames.push_back ("Gabriel"); moreNames.push_back ("Palo"); moreNames.push_back ("Lucy"); moreNames.push_back ("Dale"); moreNames.push_back ("Herman"); showCustomersInLine (); cin.get (); cout << "Jennifer just took cuts! \n\n"; moreNames.push_front ("Jennifer"); showCustomersInLine (); return 0; } void showCustomersInLine () { for (int x = 0; x < moreNames.size (); x++) cout << moreNames [x] << "\n"; return; }