Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MAX_SIZE 101
- int A[MAX_SIZE];
- int top=-1;
- void push(int x){
- if (top== MAX_SIZE -1){
- printf("Error: stack overflow\n");
- return;
- }
- top++;
- A[top]=x;
- }
- void pop(){
- if (top== -1){
- printf("Error: No element to pop\n");
- return;
- }
- top--;
- }
- int Top(){
- return A[top];
- }
- int isEmpty(){
- if (top==-1) return 1;
- else return 0;
- }
- void printStack(){
- int i;
- printf("Stack: ");
- for (i=0;i<=top;i++)
- printf("%i ",A[i]);
- printf("\n");
- }
- int main()
- {
- char st[40];
- printf("Enter a string:\n");
- scanf("%s", st);
- int i=0;
- while (i<strlen(st)){
- if (st[i]== '(') push(1); // ()=1
- if (st[i]== '[') push(2); // []=2
- if (st[i]== '{') push(3);
- if (st[i]== ')')
- if(Top()==1) pop(); else i=100;
- if (st[i]== ']')
- if(Top()==2) pop(); else i=100;
- if (st[i]== '}')
- if(Top()==3) pop(); else i=100;
- i++;
- }
- (isEmpty() )? printf("\nEmpty\n"):printf("\nNo Empty\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement