Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Prog ramming Assignment:Abstract Data Type Queue Application: Categorizing Data

ID: 3601014 • Letter: P

Question

Prog ramming Assignment:Abstract Data Type Queue Application: Categorizing Data Problem Specification Categorizing data: it is often necessacy to destroying their relative positional order. As a simple example consider a List of numbers that is maintaining their original elative positiona [ea r range daa wihout to be grouped into categories while l ordet Example Given the data set: 3 22 12 6 10 34 65 29 9 30 81 4 5 19 20 57 44 99 ategorize the data into four different group.s 1 to 9, 10 to 19, 20 to 29, and30 or mote The cesult is the categorized data: Categor l to 9 10 to 19 20 to 29 30 or more 12 10 19 22 29 20 34 65 30 8 57 44 99 ther a list categorized açcording The result is not a sorted list but ra to the specific requirements for the categories. group have kept their relative positional order. The numbers in each The underlying ADT for this application program is the ADT: Queue whose implementation has already been completed. Consequently, it should be possible to write this applica become involved with any "low level tion program without having to " data structure details. Prograiruning Notes This program should make use of the ARRAY IMPLEMENTATION of the ADT: queue This requires: struct QUEUE INFO RC i[30]; back; and the function prototypes / function definitions for create queueq) empty (qenque g, (q, i purge(q 2. For this application ion program, define INFO RC to be equivalent to the INFO data type int: typedef int INFO RC; Note this must be placed before the data structure declara QUEUE

Explanation / Answer

#include #include struct node { int info; struct node *ptr; }*top,*top1,*temp; int topelement(); void push(int data); void pop(); void empty(); void display(); void destroy(); void stack_count(); void create(); int count = 0; void main() { int no, ch, e; printf(" 1 - Push"); printf(" 2 - Pop"); printf(" 3 - Top"); printf(" 4 - Empty"); printf(" 5 - Exit"); printf(" 6 - Dipslay"); printf(" 7 - Stack Count"); printf(" 8 - Destroy stack"); create(); while (1) { printf(" Enter choice : "); scanf("%d", &ch); switch (ch) { case 1: printf("Enter data : "); scanf("%d", &no); push(no); break; case 2: pop(); break; case 3: if (top == NULL) printf("No elements in stack"); else { e = topelement(); printf(" Top element : %d", e); } break; case 4: empty(); break; case 5: exit(0); case 6: display(); break; case 7: stack_count(); break; case 8: destroy(); break; default : printf(" Wrong choice, Please enter correct choice "); break; } } } /* Create empty stack */ void create() { top = NULL; } /* Count stack elements */ void stack_count() { printf(" No. of elements in stack : %d", count); } /* Push data into stack */ 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++; } /* Display stack elements */ void display() { top1 = top; if (top1 == NULL) { printf("Stack is empty"); return; } while (top1 != NULL) { printf("%d ", top1->info); top1 = top1->ptr; } } /* Pop Operation on stack */ void pop() { top1 = top; if (top1 == NULL) { printf(" Error : Trying to pop from empty stack"); return; } else top1 = top1->ptr; printf(" Popped value : %d", top->info); free(top); top = top1; count--; } /* Return top element */ int topelement() { return(top->info); } /* Check if stack is empty or not */ void empty() { if (top == NULL) printf(" Stack is empty"); else printf(" Stack is not empty with %d elements", count); } /* Destroy entire stack */ void destroy() { top1 = top; while (top1 != NULL) { top1 = top->ptr; free(top); top = top1; top1 = top1->ptr; } free(top1); top = NULL; printf(" All stack elements destroyed"); count = 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote