-
Notifications
You must be signed in to change notification settings - Fork 1
/
8_11_Two_integer_Queue
57 lines (51 loc) · 1.15 KB
/
8_11_Two_integer_Queue
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <vector>
#include <stdexcept>
#include <cmath>
using namespace std;
class queue
{
private:
unsigned long int num, zeroes;
public:
queue()
{
num = 0;
zeroes = 0;
}
void enqueue(int a){
num = a*(pow(10,zeroes)) + num;
zeroes++;
}
int dequeue(){
if(zeroes > 0){
int ret = num%10;
num /= 10;
zeroes--;
return ret;
}
throw length_error("empty queue");
}
};
int main(){
vector<int> v = {0, 0, 0, 0, 0, 0, 7 ,6, 0 , 0, 0 , 0 , 2, 1};
queue q;
for(int i=0; i<v.size(); i++){
q.enqueue(v[i]);
}
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
cout << q.dequeue() << endl;
return 0;
}