Created
November 11, 2014 21:41
-
-
Save matutter/b9355b31a895a3192212 to your computer and use it in GitHub Desktop.
using queues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <queue> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| using namespace std; | |
| int main(int argc, char const *argv[]) | |
| { | |
| srand(time(NULL)); | |
| queue<int> myqueue, other_queue; | |
| for (int i = 0; i < 10; ++i) | |
| myqueue.push( rand() % 100 ); | |
| while( !myqueue.empty() ) | |
| { | |
| cout << "\r REMEMBER THIS! " << myqueue.front() << flush; | |
| other_queue.push( myqueue.front() ); | |
| myqueue.pop(); | |
| usleep(400000); | |
| } | |
| cout << "\r CAN YOU REMEMBER IT? " << endl; | |
| for (int i = 0; i < 10; ++i) | |
| { | |
| int n; | |
| cout << "Enter number " << i+1 << " : " ; | |
| cin >> n; | |
| myqueue.push(n); | |
| } | |
| while( !myqueue.empty() ) | |
| { | |
| cout << myqueue.front() << " " << other_queue.front(); | |
| cout << (myqueue.front()==other_queue.front()?" << AWESOME": "") << endl; | |
| myqueue.pop(); | |
| other_queue.pop(); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment