▸ Implement two primary functions of queue: ▪ enqueue(): insert a node at the tail of a queue ▪ dequeue(): remove a node

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: 899603
Joined: Mon Aug 02, 2021 8:13 am

▸ Implement two primary functions of queue: ▪ enqueue(): insert a node at the tail of a queue ▪ dequeue(): remove a node

Post by answerhappygod »

Implement Two Primary Functions Of Queue Enqueue Insert A Node At The Tail Of A Queue Dequeue Remove A Node 1
Implement Two Primary Functions Of Queue Enqueue Insert A Node At The Tail Of A Queue Dequeue Remove A Node 1 (30.62 KiB) Viewed 38 times
Implement Two Primary Functions Of Queue Enqueue Insert A Node At The Tail Of A Queue Dequeue Remove A Node 2
Implement Two Primary Functions Of Queue Enqueue Insert A Node At The Tail Of A Queue Dequeue Remove A Node 2 (36.32 KiB) Viewed 38 times
▸ Implement two primary functions of queue: ▪ enqueue(): insert a node at the tail of a queue ▪ dequeue(): remove a node from head of a queue and free the memory that was allocated to the node ▸ There is a sample code in the next slide. Enter your choice: ? 1 1 to add an item to the queue Enter a character: B The queue is: 2 to remove an item from the queue 3 to end A> B> NULL 71 Enter a character: A ? 1 The queue is: Enter a character: C A --> NULL The queue is: A - B - C --> NULL 71 Enter a character: B ? 2 A has been dequeued. The queue is: A--> B> NULL The queue is: B> C> NULL

PILTUUR LUI. #include <stdlib.h> struct queueNodel char data: struct queueNode nextPtr: }; typedef struct queueNode QueueNode: typedef QueueNode QueueNodePtr: void print Queue(QueueNodePtr currentPtr); int IsEmpty(QueueNodePtr headptr); char dequeue(QueueNodePtr headPtr, QueueNodePtr tailPtr): void enqueue QueueNodePtr headPtr. QueueNodePtr tailPtr, char value); void instructions(): void instructions() ( printf("Enter your choice: "); printf("et! to add an item to the queue #n"); printf("#t2 to remove an ites from the queue #n"); printf("t3 to endtn"): int isEmpty(QueueNodePtr headPtr) ( return headPtr = NULL: void print Queue(QueueNodePtr currentPtr) ( if (IsEmpty(currentPtr)) ( printf("Queue is emptynen): ) else ( printf("The queue is n"); while (currentPtr = NULL) { } printf("NULL "); printf("%c, currentPtr->data); currentPtr currentPtr->nextPtr: The main t QueueNodePtr headPtr NULL QueueNodePtr tailPtr = NULL: int choice: char item: instructions(): printf(" "); scanf-s("%d", Echoice): while (choice 1-3) ( switch (choice) ( case 1: while (1getchar()); printf("Enter a character: "); iten getchar(); enqueue(sheadPtr, StailPtr. item); printQueue(headptr); break; while (igetchar()); if (isEmpty(headPtr)) ( ites dequeuel SheadPtr. StailPtr): printf("%c has been dequeued #n", item); ) print Queue(headPtr); break: while (1getchar()); printf("Invalid choice. #ntn"); instructions(); break: :) printf(" "); scanf_s("%d", &choice): ) printf("End of run. n"); return 0: case 2: default:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply