FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Data-Structures/Stack/evaluation_prefix.cpp at master · coderhersh/Data-Structures · GitHub
coderhersh
/
Data-Structures
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
Data-Structures
/
Stack
/
evaluation_prefix.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (35 loc) · 973 Bytes
Breadcrumbs
Data-Structures
/
Stack
/
evaluation_prefix.cpp
Copy path
File metadata and controls
43 lines (35 loc) · 973 Bytes
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
#
include
<
bits/stdc++.h
>
using
namespace
std
;
bool
isOperator
(
char
c) {
if
(c ==
'
*
'
|| c ==
'
/
'
|| c ==
'
+
'
|| c ==
'
-
'
|| c ==
'
^
'
) {
return
true
;
}
return
false
;
}
int
evaluate
(
int
second,
char
o,
int
first) {
switch
(o) {
case
'
+
'
:
return
second + first;
case
'
-
'
:
return
second - first;
case
'
*
'
:
return
second * first;
case
'
/
'
:
return
second / first;
case
'
^
'
:
return
pow
(second, first);
}
}
int
prefixEvaluation
(string &String) {
stack<
int
> Stack;
for
(
int
i = String.
size
() -
1
; i >=
0
; --i) {
if
(!
isOperator
(String[i])) {
Stack.
push
(
int
(String[i] -
'
0
'
));
}
else
{
int
first = Stack.
top
();
Stack.
pop
();
int
second = Stack.
top
();
Stack.
pop
();
Stack.
push
(
evaluate
(second, String[i], first));
}
}
return
Stack.
top
();
}
int
main
(
void
) {
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL