Horje
stack algorithm in c++ Code Example
stack c++
#include <bits/stdc++.h> 

stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5
stack data structure c++
#include<iostream>
#include<stack>
using namespace std;
bool isValid(string s) {
	stack<char> st;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == '(' || s[i] == '{' || s[i] == '[')
			st.push(s[i]);
		if (!st.empty())
		{
			if (s[i] == ')')
			{
				if (st.top() == '(')
				{
					st.pop();
					continue;
				}
				else
					break;
			}
			//
			if (s[i] == '}')
			{
				if (st.top() == '{')
				{
					st.pop();
					continue;
				}
				else
					break;
			}
			//
			if (s[i] == ']')
			{
				if (st.top() == '[')
				{
					st.pop();
					continue;
				}
				else
					break;
			}
		}
		else
			return false;
	}
	return st.empty() ? true : false;
}
int main()
{
	string s;
	cin >> s;
	cout << isValid(s) << "\n";
	return 0;
}
stack algorithm in c++
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class stack




Cpp

Related
how to sort a string alphabetically in c++ Code Example how to sort a string alphabetically in c++ Code Example
c++ require keyword Code Example c++ require keyword Code Example
varint index Code Example varint index Code Example
empty 2d array as a member of a class class c++ Code Example empty 2d array as a member of a class class c++ Code Example
how to call subclass override method in c++ Code Example how to call subclass override method in c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7