TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
paranthesis_matching.cpp
Go to the documentation of this file.
1
8
#include <iostream>
9
#ifdef _MSC_VER
10
#include <string>
// Visual Studio C requires this include
11
#else
12
#include <cstring>
13
#endif
14
16
#define MAX 100
17
20
char
stack
[MAX];
21
23
int
stack_idx
= -1;
24
26
void
push(
char
ch) {
stack
[++
stack_idx
] = ch; }
27
29
char
pop() {
return
stack
[
stack_idx
--]; }
30
32
36
char
opening
(
char
ch) {
37
switch
(ch) {
38
case
'}'
:
39
return
'{'
;
40
case
']'
:
41
return
'['
;
42
case
')'
:
43
return
'('
;
44
case
'>'
:
45
return
'<'
;
46
}
47
return
'\0'
;
48
}
49
50
int
main
() {
51
std::string
exp
;
52
int
valid = 1, i = 0;
53
std::cout <<
"Enter The Expression : "
;
54
std::cin >>
exp
;
55
56
while
(valid == 1 && i <
exp
.length()) {
57
if
(exp[i] ==
'('
|| exp[i] ==
'{'
|| exp[i] ==
'['
|| exp[i] ==
'<'
) {
58
push(exp[i]);
59
}
else
if
(
stack_idx
>= 0 &&
stack
[
stack_idx
] ==
opening
(exp[i])) {
60
pop();
61
}
else
{
62
valid = 0;
63
}
64
i++;
65
}
66
67
// makes sure the stack is empty after processsing (above)
68
if
(valid == 1 &&
stack_idx
== -1) {
69
std::cout <<
"\nCorrect Expression"
;
70
}
else
{
71
std::cout <<
"\nWrong Expression"
;
72
}
73
74
return
0;
75
}
stack
for std::invalid_argument
Definition
stack.hpp:19
main
int main()
Main function.
Definition
generate_parentheses.cpp:110
ciphers::elliptic_curve_key_exchange::exp
uint256_t exp(uint256_t number, uint256_t power, const uint256_t &mod)
This function calculates number raised to exponent power under modulo mod using Modular Exponentiatio...
Definition
elliptic_curve_key_exchange.cpp:78
opening
char opening(char ch)
Definition
paranthesis_matching.cpp:36
stack_idx
int stack_idx
pointer to track stack index
Definition
paranthesis_matching.cpp:23
others
paranthesis_matching.cpp
Generated by
1.18.0