diff --git a/Applications/Computational_Algorithm_Application/stack.cpp b/Applications/Computational_Algorithm_Application/stack.cpp new file mode 100644 index 0000000..063a6f3 --- /dev/null +++ b/Applications/Computational_Algorithm_Application/stack.cpp @@ -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 +using namespace std; + + +void print(vectorarr){ + cout<<"operation performed in order: "; + for (int i = 0; i < arr.size(); i++) + { + cout<&s,stack&t,vectorarr){ + if(s.size()==0){ + cout<<"nothing to undo"; + return; + } + t.push(s.top()); + s.pop(); + cout<<"undo done:"<&s,stack&t,vectorarr){ + if(t.size()==0){ + cout<<"nothing to redo"<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"<>n; + + vectorarr; + stacks; + stackt; + + for(int i=0;i>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; +} \ No newline at end of file diff --git a/Computational Algorithms/README.md b/Computational Algorithms/README.md deleted file mode 100644 index 8b13789..0000000 --- a/Computational Algorithms/README.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/DSA algorithms/Two Pointer/Kadane's_Algorithm.bin b/DSA algorithms/Two Pointer/Kadane's_Algorithm.bin deleted file mode 100644 index e46125f..0000000 Binary files a/DSA algorithms/Two Pointer/Kadane's_Algorithm.bin and /dev/null differ diff --git a/DSA algorithms/Two Pointer/Kadane's_Algorithm.cpp b/DSA algorithms/Two Pointer/Kadane's_Algorithm.cpp deleted file mode 100644 index 01b7d22..0000000 --- a/DSA algorithms/Two Pointer/Kadane's_Algorithm.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*KADANE'S ALGORITHM for finding maximum possible contiguous subarray sum*/ - -/*Algorithm - 1)initialize an integer(let's say int sum) with minimum value(INT_MIN) - 2)inititalize an integer(let's say int current) with value 0 - 3)iterate over an array(int a[]) - 4)update current=max(a[i],a[i]+current) - 4)if (current>=sum) update sum, make it equal to current - 5)if (current -using namespace std; - - -int maxSubArray(vector nums) { - - int ans=INT_MIN; - int cur=0; - for(int num:nums){ - cur=max(num,cur+num); - if(cur>=ans){ - ans=cur; - } - else{ - continue; - } - } - return ans; -} - -/*TWO POINTER APPROACH comes in play when we want to find the length of max subarray*/ -/* just initialize 3 more integers to save start & end indexes as 0 - update end whenever sum increases - update start whenever sum decreases -} -*/ -int main(){ - vectora={1,-2,-3,4,-1,2,1,-5,4}; - int ans=maxSubArray(a); - cout< -using namespace std; - -int find(int node,vector&parent){ - //finding the parent node - while(parent[node]!=node){ - node=parent[node]; - } - return node; -} - -void Union(int i,int j,vector&parent){ - // union of node, i.e, setting parent as same. - int iroot=find(i,parent); - int jroot=find(j,parent); - if(iroot!=jroot){ - parent[jroot]=iroot; - } -} - -bool dsu(vector>& edges) { - //setting parent of each node - vectorparent(edges.size()+1); - for(int i=0;i>graph={{1,2},{2,3},{3,4},{1,5},{1,4}}; - /* - graph is: - 2--1--5 - | | - 3--4 - */ - bool ans= dsu(graph); - - if(ans)cout<<"graph is cyclic!"< -using namespace std; - -int find(int node,vector&parent){ - //finding the parent node - while(parent[node]!=node){ - node=parent[node]; - } - return node; -} - -void Union(int i,int j,vector&parent){ - // union of node, i.e, setting parent as same. - int iroot=find(i,parent); - int jroot=find(j,parent); - if(iroot!=jroot){ - parent[jroot]=iroot; - } -} - -bool dsu(vector>& edges) { - //setting parent of each node - vectorparent(edges.size()+1); - for(int i=0;i>graph={{1,2},{2,3},{3,4},{1,5},{1,4}}; - /* - graph is: - 2--1--5 - | | - 3--4 - */ - bool ans= dsu(graph); - - if(ans)cout<<"graph is cyclic!"<