-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyStackTest.h
More file actions
74 lines (59 loc) · 1.27 KB
/
Copy pathmyStackTest.h
File metadata and controls
74 lines (59 loc) · 1.27 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// This file tests the generated input by implementing it in a self-defined Stack.
#include <iostream>
#include <ctime>
using namespace std;
#include "myStack.h"
void myStackTest(int inp[], int count_add, int count_search, int count_del)
{
myStack st, temp;
clock_t t1 = clock();
for(int i=0; i<count_add; i++)
st.push(inp[i]);
clock_t t2 = clock();
for(int i=0; i<count_search; i++)
{
while(!st.empty())
{
if(st.top() == inp[i+count_add])
{
//cout << "YES\n";
break;
}
temp.push(st.top());
st.pop();
}
if(st.size()==0)
{
//cout << "NO\n";
}
while(!temp.empty())
{
st.push(temp.top());
temp.pop();
}
}
clock_t t3 = clock();
for(int i=0; i<count_del; i++)
{
while(!st.empty())
{
if(st.top() == inp[i + count_add + count_search])
{
st.pop();
break;
}
temp.push(st.top());
st.pop();
}
while(!temp.empty())
{
st.push(temp.top());
temp.pop();
}
}
clock_t t4 = clock();
cout << "\nSelf-defined Stack done! The result times(in microseconds are) : \n";
cout << "Inserting " << count_add << " values : " << float(t2-t1) << "\n";
cout << "Searching " << count_search << " values : " << float(t3-t2) << "\n";
cout << "Deleting " << count_del << " values : " << float(t4-t3) << "\n";
}