This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A Stack based C++ program to find next | |
// greater element for all array elements. | |
#include <bits/stdc++.h> | |
using namespace std; | |
/* prints element and NGE pair for all | |
elements of arr[] of size n */ | |
void printNGE(int arr[], int n) { | |
stack < int > s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
C++ Program to check for balanced parentheses in an expression using stack. | |
Given an expression as string comprising of opening and closing characters | |
of parentheses - (), curly braces - {} and square brackets - [], we need to | |
check whether symbols are balanced or not. | |
*/ | |
#include<iostream> | |
#include<stack> | |
#include<string> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C++ linear time solution for stock span problem | |
#include <iostream> | |
#include <stack> | |
using namespace std; | |
// A stack based efficient method to calculate | |
// stock span values | |
void calculateSpan(int price[], int n, int S[]) | |
{ | |
// Create a stack and push index of first |