/* Stack/Queue operations void push(struct stack_queue **p, int number, int type); Example: struct stack_queue link_base; push(&link_base,number_to_be_pushed,0); 0 -> Stack 1 -> Queue int pop(struct stack_queue **p); Example: struct stack_queue link_base; variable=pop(&link_base); void display(struct stack_queue *p); Example: struct stack_queue link_base; display(link_base); int count(struct stack_queue *p); Example: struct srack_queue link_base; variable=count(link_base); */ //Structure for the stack_queue struct stack_queue { int key; struct stack_queue *next; }; //Push an item into the stack/queue void push(struct stack_queue **b, int n, int t) { struct stack_queue *q,*r; q=*b; if(t==0) { if(q==NULL) { q=(struct stack_queue *)malloc(sizeof(struct stack_queue *)); q->key=n; q->next=NULL; *b=q; } else { r=(struct stack_queue *)malloc(sizeof(struct stack_queue *)); r->key=n; r->next=q; *b=r; } } else if (t==1) { if(q==NULL) { q=(struct stack_queue *)malloc(sizeof(struct stack_queue *)); q->key=n; q->next=NULL; *b=q; } else { while(q->next!=NULL) q=q->next; r=(struct stack_queue *)malloc(sizeof(struct stack_queue *)); r->key=n; r->next=NULL; q->next=r; } } } //Pop an item from the stack/queue int pop(struct stack_queue **b) { struct stack_queue *p; int n; p=*b; if(p==NULL){return 0;} n=p->key; *b=p->next; free(p); return n; } //Count the number of items in the stack int count(struct stack_queue *b) { struct stack_queue *p; int c=0; p=b; while(p!=NULL) { c++; p=p->next; } return c; } //Display the contents of the stack/queue void display(struct stack_queue *b) { struct stack_queue *p; p=b; if(count(p)==0){printf("\n Data structure is empty!");return;} while(p!=NULL) { printf("\n Element is %d",p->key); p=p->next; } } //Use struct stack_queue from now on as DStructure typedef struct stack_queue DStructure;