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

Please program in C Develop a program that creates a queue of numbers. Follow th

ID: 3815596 • Letter: P

Question

Please program in C

Develop a program that creates a queue of numbers. Follow the instruction below to develop the program 1) Declare structure Node Type as follows: typedef struct NodeType int number struct NodeType next NodeType 2) Write the following functions: This function prompts the user for a sequence of numbers. As each number is read, memory is allocated for a node, the number is saved there, and the node is added to the queue. A negative number marks the end of the sequence The function then returns the pointer to the head of the queue void displaya (NodeType "head); This function receives a pointer to the head of a queue and displays numbers in the queue If the queue is empty, it displays an appropriate message. 3) Main function In the main function declare NodeType *head NULL; Issue call head createQ (head) to create a queue and then call displayQ (head) to display the contents of the queue. Note: You may change the names of the function and its parameters. An example illustrating interaction with the program follows

Explanation / Answer

#include<stdio.h>
#include <stdlib.h>
struct Queue
{
   int data;
   struct Queue *next;
};
struct Queue *front=NULL;
struct Queue *rear=NULL;
void enqueue(int x)
{
   struct Queue *temp;
   temp=(struct Queue *)malloc(sizeof(struct Queue *));
   temp->data=x;
   temp->next=NULL;
   if(front==NULL && rear==NULL)
   {
       front=rear=temp;
       return;
   }
   rear->next=temp;
   rear=temp;
}
void display()
{
   struct Queue *temp=front;
   while(temp)
   {
       printf("%d ",temp->data);
       temp=temp->next;
   }
   printf(" ");
}
struct Queue *createQ()
{
   int n;
   do
   {
       printf(" enter the numbers : ");
       scanf("%d",&n);
       if(n!=-1)
       enqueue(n);
   }while(n!=-1);
}
int main()
{
   createQ();
   display();
   return 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