FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
StackMachine/Example.cpp at main · ckrique/StackMachine · GitHub
ckrique
/
StackMachine
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
StackMachine
/
Example.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (48 loc) · 1.15 KB
Breadcrumbs
StackMachine
/
Example.cpp
Copy path
File metadata and controls
59 lines (48 loc) · 1.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#includ
e
<iostrea
m
>
#
include
<
stack
>
using
namespace
std
;
#
include
"
StackMAchine.h
"
class
Example
:
public
StackMachine
{
public:
void
run
() {
//
infix 10 + 3 * 5 / 3
//
posfix 10 3 5 * 3/+
vector<string> tokensPostfix;
tokensPostfix.
push_back
(
"
10
"
);
tokensPostfix.
push_back
(
"
3
"
);
tokensPostfix.
push_back
(
"
5
"
);
tokensPostfix.
push_back
(
"
*
"
);
tokensPostfix.
push_back
(
"
3
"
);
tokensPostfix.
push_back
(
"
/
"
);
tokensPostfix.
push_back
(
"
+
"
);
string strTokens;
for
(std::vector<std::string>::iterator c = tokensPostfix.
begin
(); c != tokensPostfix.
end
(); c++
/*
C++ :-) C++ :-/
*/
)
{
strTokens += *c;
strTokens +=
"
"
;
}
cout << strTokens << endl;
for
(std::vector<std::string>::iterator c = tokensPostfix.
begin
(); c != tokensPostfix.
end
(); c++
/*
C++ :-) C++ :-/
*/
) {
std::cout << *c << std::endl;
if
(*c ==
"
"
)
continue
;
else
if
(*c ==
"
+
"
)
add
();
else
if
(*c ==
"
-
"
)
sub
();
else
if
(*c ==
"
*
"
)
mul
();
else
if
(*c ==
"
/
"
)
div
();
else
if
(*c !=
"
(
"
&& *c !=
"
)
"
)
push
(
stoi
(*c));
printStackItens
();
}
print
();
}
};
int
main
()
{
Example example;
example.
run
();
}
Back
|
FazBrowse Home
|
New Git URL