Page 1 of 1

Subject-Data Structures #include #include typedef struct node { int info: struct node *next; ; }nodet

Posted: Fri Apr 29, 2022 7:09 am
by answerhappygod
Subject Data Structures Include Stdio H Include Stdlib H Typedef Struct Node Int Info Struct Node Next Nodet 1
Subject Data Structures Include Stdio H Include Stdlib H Typedef Struct Node Int Info Struct Node Next Nodet 1 (48.8 KiB) Viewed 26 times
using similar type of code writing method, write a c program to
represent implementation of a QUEUE using linked list and DOUBLE
POINTER also please explain every line of code thank you.
Subject-Data Structures #include<stdio.h> #include<stdlib.h> typedef struct node { int info: struct node *next; ; }nodetype nodetype *push(nodetype *); nodetype *pop(nodetype*); void display(nodetype *); int main() = int ch; nodetype * top = NULL; printf("\t1. Push\n\12. Pop\n\13. Display\n\14. Exit\n"); do { printf("Enter choice: "); scanf("%d", &ch); switch(ch) { case 1: top = push(top); break; case 2: if(top == NULL) printf("Stack is empty.\n"); else top = pop(top); break; case 3: if(top == NULL) printf("Stack is empty.\n"); else printf("Stack content: \n"); display(top); break; case 4: printf("Exit."); break; default: printf("Enter a valid choice. \n"); } }while(ch != 4); return 0; ) nodetype *push(nodetype *top) intx nodetype *p = NULL; printf("Enter a value: "); scanf("%d",&x); p = (nodetype *)malloc(sizeof(nodetype)); if(p == NULL) ) printf("\nNot enough memory); else { p->info = x p->next = top: topp: } return top: > nodetype *pop(nodetype *top) nodetype *p = NULL p = top: printf("Poped number: %d\n", p->info); top = top->next; free(p) return top: } void display(nodetype #top) ( while(top != NULL) { printf("%d\n", top->Info); top = top->next } OUTPUT: 1. Push 2. Pop 3. Display 4. Exit Enter choice: 1 Enter a value: 50 Enter choice: 1 Enter a value: 60 Enter choice: 1 Enter a value: 70 Enter choice: 2 Poped number: 70 Enter choice: 3 Stack content: 60 50 Enter choice: 4