style: format code

This commit is contained in:
yanglbme
2019-08-21 10:10:08 +08:00
parent abc0d365de
commit 69ddc9fc52
101 changed files with 3154 additions and 2984 deletions

View File

@@ -1,5 +1,5 @@
#include<iostream>
#include<string>
#include <iostream>
#include <string>
using namespace std;
@@ -10,55 +10,66 @@ using namespace std;
char stack[MAX];
int top = -1;
void push(char ch){
stack[ ++top ] = ch;
void push(char ch)
{
stack[++top] = ch;
}
char pop(){
return stack[ top-- ];
char pop()
{
return stack[top--];
}
// -------------- end stack -----------
char opening(char ch){
switch(ch){
case '}':
return '{';
case ']':
return '[';
case ')':
return '(';
case '>':
return '<';
char opening(char ch)
{
switch (ch)
{
case '}':
return '{';
case ']':
return '[';
case ')':
return '(';
case '>':
return '<';
}
}
int main(){
int main()
{
string exp;
int valid = 1, i = 0;
cout<<"Enter The Expression : ";
cout << "Enter The Expression : ";
cin >> exp;
while (valid == 1 && i < exp.length()){
if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<'){
push(exp[i]);
}
else if (top >= 0 && stack[top] == opening(exp[i])){
pop();
}
else{
valid = 0;
}
i++;
while (valid == 1 && i < exp.length())
{
if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<')
{
push(exp[i]);
}
else if (top >= 0 && stack[top] == opening(exp[i]))
{
pop();
}
else
{
valid = 0;
}
i++;
}
// makes sure the stack is empty after processsing (above)
if (valid == 1 && top == -1){
cout<<"\nCorrect Expression";
// makes sure the stack is empty after processsing (above)
if (valid == 1 && top == -1)
{
cout << "\nCorrect Expression";
}
else{
cout<<"\nWrong Expression";
else
{
cout << "\nWrong Expression";
}
return 0;