Skip to content

Instantly share code, notes, and snippets.

@matutter
Created November 11, 2014 21:41
Show Gist options
  • Select an option

  • Save matutter/b9355b31a895a3192212 to your computer and use it in GitHub Desktop.

Select an option

Save matutter/b9355b31a895a3192212 to your computer and use it in GitHub Desktop.
using queues
#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