From 4450f7780abd40ad9d3099874240dd6f7d8deefb Mon Sep 17 00:00:00 2001 From: Anup Kumar Panwar Date: Tue, 30 Aug 2016 15:01:33 +0530 Subject: [PATCH] comment changed --- Insertion Sort.cpp | 11 ++++--- Paranthesis Matching.cpp | 66 ++++++++++++++++++++++++++++++++++++++++ Tower of Hanoi.cpp | 12 ++------ 3 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 Paranthesis Matching.cpp diff --git a/Insertion Sort.cpp b/Insertion Sort.cpp index 1123543d5..45e860dde 100644 --- a/Insertion Sort.cpp +++ b/Insertion Sort.cpp @@ -1,21 +1,22 @@ -//Bubble Sort +//Insertion Sort #include using namespace std; int main() { - int Array[6]; + int n; + int Array[n]; cout<<"\nEnter any 6 Numbers for Unsorted Array : "; //Input - for(int i=0; i<6; i++) + for(int i=0; i>Array[i]; } //Sorting - for(int i=1; i<6; i++) + for(int i=1; i +#include +#include +#include +using namespace std; + +char stack[100]; +int top=0; + +void push(char ch) +{ + stack[top++]=ch; +} + +char pop() +{ + return stack[--top]; +} + +bool check(char x, char y) +{ + if ( ( x=='(' && y==')' ) || ( x=='{' && y=='}' ) || ( x=='[' && y==']' ) || ( x=='<' && y=='>' ) ) + { + return true; + } + else + { + return false; + } +} + + + +int main() +{ + char exp[100]; + cout<<"Enter The Expression : "; + gets(exp); + for (int i = 0; i < strlen(exp); i++) + { + if (exp[i]=='(' || exp[i]=='{' || exp[i]=='[' || exp[i]=='<') + { + push(exp[i]); + //show(); + } + else if (exp[i]==')' || exp[i]=='}' || exp[i]==']' || exp[i]=='>') + { + if(!check(pop(), exp[i])) + { + cout<<"\nWrong Expression"; + exit(0); + } + } + } + + if(top==0) + { + cout<<"Correct Expression"; + } + else + { + cout<<"\nWrong Expression"; + } + + return 0; +} diff --git a/Tower of Hanoi.cpp b/Tower of Hanoi.cpp index a432d3574..f9b363784 100644 --- a/Tower of Hanoi.cpp +++ b/Tower of Hanoi.cpp @@ -65,7 +65,7 @@ int main() int no; - cout << "Enter number of discs : " ; + cout << "\nEnter number of discs : " ; cin >> no; for (int i = no; i >0; i--) @@ -74,10 +74,7 @@ int main() }; - for (int i = (F.top)-1; i >=0; i--) - { - cout<=0; i--) - { - cout<<"\n"<