Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file for application folder #5 #50

Closed
Closed
Show file tree
Hide file tree
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
131 changes: 131 additions & 0 deletions Applications/Computational_Algorithm_Application/stack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//STACK APPLICATION IN REAL LIFE

/*in real world stack sata structure is used for
1)backward and forward button in browsers
2)memory management in computer programming
3)delimiter checking
4)undo and redo options
5)implementation recursion in programming
etc.
*/

/*here we look at some of the real life implementation on small scale which can be enlarged for large data later
1)undo and redo
2)delimiter

code is very simple and self explanatory so no comments are given.
*/

#include<bits/stdc++.h>
using namespace std;


void print(vector<int>arr){
cout<<"operation performed in order: ";
for (int i = 0; i < arr.size(); i++)
{
cout<<arr[i]<<' ';
}
cout<<endl;
}

void Undo(stack<int>&s,stack<int>&t,vector<int>arr){
if(s.size()==0){
cout<<"nothing to undo";
return;
}
t.push(s.top());
s.pop();
cout<<"undo done:"<<endl;
for (int i = 0; i < s.size(); i++)
{
cout<<arr[i]<<' ';
}
cout<<endl;
return;
}

void Redo(stack<int>&s,stack<int>&t,vector<int>arr){
if(t.size()==0){
cout<<"nothing to redo"<<endl;
return;
}
s.push(t.top());
t.pop();
cout<<"redo done:"<<endl;
for (int i = 0; i < s.size(); i++)
{
cout<<arr[i]<<' ';
}
cout<<endl;
return;
}
//delimiter is a way of checking if an sequence have an end for every start
// here look that application with use of brackets balancing.

void delimiterCheck(string l){
stack<char>s;
for (int i = 0; i < l.length(); i++)
{
if(l[i]=='('||l[i]=='{'||l[i]=='['){
s.push(l[i]);
}
else if (l[i]==')'||l[i]=='}'||l[i]==']')
{
if(s.empty()==true){
cout<<"brackets are not balanced"<<endl;
return;
}

char top=s.top();
if((top=='('&&l[i]==')')||(top=='{'&&l[i]=='}')||(top=='['&&l[i]==']')){
s.pop();
}
else {
cout<<"brackets are not balanced";
return;
}
}
}
if(s.empty()==true){
cout<<"brackets are balanced"<<endl;
return;

}
else{
cout<<"brackets are not balanced"<<endl;
return;
}
}

int main(){
int n;
cout<<"enter number of operation you want to perform: ";
cin>>n;

vector<int>arr;
stack<int>s;
stack<int>t;

for(int i=0;i<n;i++)
{
int k;
cout<<"enter operation number you want to perform(integer value): ";
cin>>k;
arr.push_back(k);
s.push(k);
print(arr);
}

int chk=0;
cout<<"perform undo/redo/none (type 0/1/else): ";
cin>>chk;
if(chk==1)Redo(s,t,arr);
else if(chk==0)Undo(s,t,arr);

cout<<"to check bracket balancing give any operation(eg- (1+2)*5 ): ";
string l;
cin>>l;
delimiterCheck(l);
return 0;
}
1 change: 0 additions & 1 deletion Computational Algorithms/README.md

This file was deleted.

Binary file removed DSA algorithms/Two Pointer/Kadane's_Algorithm.bin
Binary file not shown.
44 changes: 0 additions & 44 deletions DSA algorithms/Two Pointer/Kadane's_Algorithm.cpp

This file was deleted.

77 changes: 0 additions & 77 deletions DSA algorithms/graphs/cyclicity_in_graph.cpp

This file was deleted.

77 changes: 0 additions & 77 deletions applications/Computational algo/visualising_disjoint_set_union.cpp

This file was deleted.

Binary file not shown.
2 changes: 0 additions & 2 deletions applications/ML Algo/README.md

This file was deleted.