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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 24 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply