Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions 17EGICS068_stack_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include<bits/stdc++.h>
#include<stack>
#include<string>
#include<iostream>
using namespace std;
bool check(string);
int main()
{
string rtr;
cout<<"enter the string";
getline(cin,rtr);
bool ans;
ans = check(rtr);
if (ans)
cout << "true";
else
cout << "false";
}
bool check(string str)
{
int i,si;
stack<char> m;
char temp;
for (i=0; i<str.length(); i++)
{
if (str[i]=='('||str[i]=='['||str[i]=='{')
{
m.push(str[i]);
continue;
}
if (m.empty())
return false;
if (str[i]==')')
{
temp = m.top();
m.pop();
if (temp=='{' || temp=='[')
return false;
break;
}
if (str[i]=='}')
{

temp = m.top();
m.pop();
if (temp=='(' || temp=='[')
return false;
break;
}
if (str[i]==']')
{

temp = m.top();
m.pop();
if (temp =='(' || temp == '{')
return false;
break;
}
}
si = str.length();
if(m.empty()||si==0)
{
return true;
}
else
{
return false;
}
}