-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
97 lines (82 loc) · 2 KB
/
main.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <string.h>
#include "Quash.h"
using namespace std;
int main(int argc, char *argv[])
{
Quash *quash = new Quash();
std::cout << "program start\n";
while(1)
{
// std::cout << "loop start\n";
char buffer[256];
std::cin.getline(buffer, 256);
string input(buffer);
//terminate
if(cin.eof())
{
std::cout << "terminate\n";
break;
}
//insert
if(input.compare(0,6,"insert") == 0)
{
// std::cout << "input is insert\n";
strtok(buffer, " ");
int numToInsert = (int)atoi(strtok(NULL,"\n"));
bool inserted = quash->insertElement(numToInsert);
if(inserted == true)
cout << "item successfully inserted\n";
//quash->printCount(numToInsert);
}
//lookup
else if(input.compare(0,6,"lookup") == 0)
{
// std::cout << "input is lookup\n";
strtok(buffer, " ");
int numToLookup = (int)atoi(strtok(NULL,"\n"));
// std::cout << "num to lookup is " << numToLookup << "\n";
bool numFound = quash->lookupElement(numToLookup);
if(numFound == true)
cout << "item found\n";
else
cout << "item not found\n";
}
//print
else if(input.compare("print") == 0)
{
// std::cout << "input is print\n";
quash->printHeap();
}
//deleteMin
else if(input.compare("deleteMin") == 0)
{
// std::cout << "input is deleteMin\n";
if (quash->isMin())
{
cout << "min item " << quash->getMin() << "successfully deleted\n";
quash->deleteMin();
}
else
cout << "min item not present since table is empty\n";
}
//delete
else if(input.compare(0,7,"delete ") == 0)
{
// std::cout << "input is delete\n";
strtok(buffer, " ");
int numToDelete = (int)atoi(strtok(NULL,"\n"));
bool deleted = quash->deleteElement(numToDelete);
if(deleted == true)
cout << "item successfully deleted\n";
else
cout << "item not present in the table\n";
}
//other inputs - make user reenter input
else
{
std::cout << "invalid input\n";
}
}
return 0;
}