-
Notifications
You must be signed in to change notification settings - Fork 0
/
stkoptr1.cpp
44 lines (40 loc) · 990 Bytes
/
stkoptr1.cpp
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
// stkoptr1.cpp -- testing stack of pointers
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "stcktp1.h"
const int Num = 10;
int main()
{
std::srand(std::time(0)); // randomize rand()
std::cout << "Please enter stack size: ";
int stacksize;
std::cin >> stacksize;
Stack<const char *> st (stacksize);
const char * in[Num] = {
" 1: Hank gILGAMESH", " 2: Kiki Ishtar",
" 3: Betty Rocker", " 4: Ian Flagranti",
" 5: WOlfgang Kibble", " 6: Portia Koop",
" 7: Joy Almondo", " 8: Xaverie Paprika",
" 9: Juan Moore", "10: Misha Mache"
};
const char * out[Num];
int processed = 0;
int nextin = 0;
while (processed < Num) {
if (st.isempty()) {
st.push(in[nextin++]);
} else if (st.isfull()) {
st.pop(out[processed++]);
} else if (std::rand() % 2 && nextin < Num) {
st.push(in[nextin++]);
} else {
st.pop(out[processed++]);
}
}
for (int i = 0; i < Num; i++) {
std::cout << out[i] << std::endl;
}
std::cout << "Bye\n";
return 0;
}