Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MAYBE FINAL
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int info;
- struct node *ptr;
- }*top, *top1, *temp;
- void push(int data);
- void pop();
- int count = 0;
- char A[100];
- int main () {
- int i ;
- printf("Enter the string : ");
- gets(A);
- for(i=0 ; A[i] != '\0' ; i++){
- if ( A[i] <= 'z' && A[i] >='a' || A[i] <= 'Z' && A[i] >='A'){
- push (A[i]);
- }
- else if (A[i] <= '9' && A[i] >='0') {
- pop ();
- }
- }
- }
- void push(int data){
- if (top == NULL)
- {
- top = (struct node *)malloc(1 * sizeof(struct node));
- top->ptr = NULL;
- top->info = data;
- }
- else
- {
- temp = (struct node *)malloc(1 * sizeof(struct node));
- temp->ptr = top;
- temp->info = data;
- top = temp;
- }
- count++;
- }
- void pop()
- {
- top1 = top;
- if (top1 == NULL)
- {
- printf("\n Error : Trying to pop from empty stack");
- return;
- }
- else{
- top1 = top1->ptr;
- printf("\n Popped value : %c\n", top->info);
- free(top);
- top = top1;
- count--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement