The complete code is as follows, but the team stack is just a change in the list.
#include <stdio.h>#include<stdlib.h>typedefstructStudent *Pnode;typedefstructStacklink *Pstack;typedefstructstudent{intdata; Pnode Next;} Node;typedefstructstacklink{Pnode Zhandi; Pnode top;} Stack; Pstack push (Pstack stack,intnum) {Pnode P= (Pnode)malloc(sizeof(Node)); Pnode temp; Pstack Q=Stack; P->data=num; if(stack==NULL) {Q= (Pstack)malloc(sizeof(Stack)); Q->zhandi=p; Q->top=p; Q->zhandi->next=NULL; Q->top->next=NULL; returnQ; } temp=q->top; Q->top=p; Q->top->next=temp; returnq;}voidprint (Pstack stack) {if(stack==NULL) {printf ("stack is empty \ n"); return; } pstack Q=Stack; Pnode P=q->top; while(p!=NULL) {printf ("%d",p->data); P=p->Next; } printf ("\ n");} Pstack pop (Pstack stack) {if(stack==NULL) {printf ("stack is empty \ n"); returnNULL; } pstack Q=Stack; Pnode Temp=q->top; if(q->top->next==NULL) {printf ("Stack has only one node, delete complete \ n"); returnNULL; } q->top=q->top->Next; returnq;}intMainvoid){ intFlag; intnum; Pstack Stack=NULL; while(1) {printf ("Select the stack or the stack: 1 for the stack, 2 for the stack, and 0 for the exit \ n"); scanf ("%d",&flag); if(flag==1) {printf ("Please select the value to be stacked: \ n"); scanf ("%d",&num); Stack=push (Stack,num); printf ("stack after printing: \ n"); print (stack); } Else if(flag==2) {Stack=pop (stack); printf ("Print the queue after the stack: \ n"); print (stack); }} Q->top=q->top->Next; returnq;}intMainvoid){ intFlag; intnum; Pstack Stack=NULL; while(1) {printf ("Select the stack or the stack: 1 for the stack, 2 for the stack, and 0 for the exit \ n"); scanf ("%d",&flag); if(flag==1) {printf ("Please select the value to be stacked: \ n"); scanf ("%d",&num); Stack=push (Stack,num); printf ("stack after printing: \ n"); print (stack); } Else if(flag==2) {Stack=pop (stack); printf ("Print the queue after the stack: \ n"); print (stack); } Else Break; } return 0;}
Programming implementation of stack/stack operations