-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.cpp
More file actions
82 lines (73 loc) · 1.39 KB
/
string.cpp
File metadata and controls
82 lines (73 loc) · 1.39 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
75
76
77
78
79
80
81
82
#ifndef STRING_CPP
#define STRING_CPP
#include <iostream>
#include <string>
#include "string.h"
using namespace std;
int prompt(){
int x;
cout << "Enter 1 for Expression Evaluation, 2 for Expression Comparison, 3 to Exit: " << endl;
cin.clear();
cin >> x;
return x;
}
int E_or_C(int x){
string s, temp;
if (x == 1){
cout << "Enter infix expression: ";
cin.ignore();
std::getline(cin, s);
Node* head = makeTree(s);
Expression ex = Expression(head);
cout << ex.Evaluate() << endl;
return ex.Evaluate();
}
else if (x == 2){
cout << "Enter two infix expressions separated by a comma: ";
cin.ignore();
std::getline(cin, temp);
int i = 0;
string s, s2;
while (temp[i] != ','){
if (temp[i] == ' '){
i++;
continue;
}
else{
s+= temp[i];
i++;
}
}
Node* head = makeTree(s);
Expression ex = Expression(head);
i++;
while (i != temp.size()){
if (temp[i] == ' '){
i++;
continue;
}
else{
s2 += temp[i];
i++;
}
}
head = makeTree(s2);
Expression ex2 = Expression(head);
return ex.Compare(ex2);
}
}
int main(){
int x = 0;
cout << "Enter 1 for Expression Evaluation, 2 for Expression Comparison: ";
cin >> x;
E_or_C(x);
int xx = prompt();
while (xx != 3){
E_or_C(xx);
xx = prompt();
if (xx == 3)
break;
}
return 0;
}
#endif