From aee06f43f5c544cebeefc0fcbd8be1c1595cd41c Mon Sep 17 00:00:00 2001 From: vyshuravella Date: Fri, 19 Oct 2018 17:14:36 +0530 Subject: [PATCH] Add Vyshnavi to Contributors list --- Stack/InfixEvaluator.java | 66 +++++++++++++++++++++ Stack/Paranthesis.java | 58 +++++++++++++++++++ Stack/PostFix.java | 66 +++++++++++++++++++++ Stack/StackChar.java | 67 ++++++++++++++++++++++ Stack/StackInt.java | 117 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 374 insertions(+) create mode 100755 Stack/InfixEvaluator.java create mode 100755 Stack/Paranthesis.java create mode 100755 Stack/PostFix.java create mode 100755 Stack/StackChar.java create mode 100755 Stack/StackInt.java diff --git a/Stack/InfixEvaluator.java b/Stack/InfixEvaluator.java new file mode 100755 index 0000000..9c09b6d --- /dev/null +++ b/Stack/InfixEvaluator.java @@ -0,0 +1,66 @@ +import java.util.Scanner; +class InfixEvaluator +{ + static int pow(int a,int b) + { + int r=1; + for(int j=0;js.prec(k)) + s.push(x); + else + { + while(s.prec(x)<=s.prec(k)) + { + b[j]=s.pop(); + j++; + k=s.peek(); + } + s.push(x); + } + } + + } + else if(x==')') + { + while(s.peek()!='(') + { + b[j]=s.pop(); + j++; + } + s.pop(); + + } + else + { + b[j]=x; + j++; + } + } + while(s.getTop()!= -1) + { + b[j]=s.pop(); + j++; + } + for(int i=0;i=(a.length-1)) + System.out.println("Stack is Full"); + else + { + top++; + a[top]=x; + } + } + public char pop() + { + if(top==(-1)) + { + return 0; + } + else + { + return a[top--]; + } + } + public int getTop() + { + return top; + } + public char peek() + { + if(top==-1) + { + return 0; + } + else + return a[top]; + } + public int prec(char x) + { + if(x=='+') + return 1; + else if(x=='-') + return 1; + else if(x=='*') + return 2; + else if(x=='/') + return 2; + else if(x=='^') + return 3; + else + return 0; + + } + +} diff --git a/Stack/StackInt.java b/Stack/StackInt.java new file mode 100755 index 0000000..bb3f995 --- /dev/null +++ b/Stack/StackInt.java @@ -0,0 +1,117 @@ + + +import java.util.Scanner; +public class StackInt +{ + private int[] arr = new int[5]; + private int top=-1; + Scanner in = new Scanner(System.in); + public StackInt() + { + arr =new int[10]; + top = -1; + } + public StackInt(int sz) + { + arr = new int[sz]; + top= -1; + } + public int getTop() + { + return top; + } + public int[] getArr() + { + return arr; + } + public void readArr(int n) + { + for(int i=0;i=(arr.length-1)) + System.out.println("Stack is Full"); + else + { + top++; + arr[top]=x; + } + } + public int pop() + { + if(top==(-1)) + { + System.out.println("Can't pop. Stack is empty"); + return 0; + } + else + { + return arr[top--]; + } + } + public int peek() + { + if(top==-1) + { + System.out.println("Can't peek"); + return 0; + } + else + return arr[top]; + } + public boolean equals(StackInt a) + { + int flag=1; + if(this.top==a.top) + { + for(int i=0;i<=top;i++) + { + if(this.arr[i]!=a.arr[i]) + flag=0; + + } + if(flag==0) + return false; + else + { + return true; + } + } + else + return false; + } + public int getm() + { + int m=arr[0]; + for(int i=0;i<=top;i++) + { + if(arr[i]