I need details comments for each line ... Thank you. The code: (Programming Language is C): #define MAXELEMENTS 5 #define MIN 0 struct queue { int items[MAXELEMENTS]; int front, rear; }; struct node { int data; struct node *next; }; typedef struct node *NODEPTR; void cqinsert(struct queue*,int); int cqdelete(struct queue*); void insert(node *head,int); int main(void) { struct queue q; int x; q.front= q.rear=-1; for(int i=0;i<5;i++) { printf("Enter input Number \n"); scanf("%d",&x); cqinsert(&q,x); } x=cqdelete(&q); NODEPTR head=(NODEPTR)malloc(sizeof(struct node)); head->data=x; head->next=NULL; for(int i=0;i<5;i++) { x=cqdelete (&q); insert(head, x); } NODEPTR save = head; do { printf("%d\n",save->data); save-save->next; } while(save!=NULL); return 0; }//end of main int cqdelete(struct queue *pq) { if(pq->front==-1) { printf("\nQueue Underflow"); exit(1); } int pq->items[pq->front]; if(pq->front==pq->rear)/*queue has only one element*/ { pq->front =-1; pq->rear =-1; } else if(pq->==MAXELEMENTS-1) pq->front=0; else pq->front=pq->front+1; return(item); } void cqinsert(struct queue *pq,int x) { if((pq->front==0 && pq->rear==MAXELEMENTS-1)||(front==pq->rear+1)) { printf("\nQueue Overflow \n"); //exit(0); return; } if(pq->front==-1) /*queue is empty*/ { pq->front=MIN; pq->rear=MIN; } else if(pq->rear==MAXELEMENTS-1) /*rear is at last position of queue*/ pq->rear=0; else pq->rear=pq->rear+1; pq->items[rear]=x; } void insert(node*head,int x){ NODEPTR p,q; q=NULL; for(p=head:p!=NULL && x>p->data;p+p->next) q=p; if(q==NULL) /*insert x at the head of the list*/ { p=(NODEPTR)malloc(sizeof(struct node)); p->data=x; p->next=head; head=p; } else{ p=(NODEPTR)malloc(sizeof(struct node)); p->data=x; p->next=q->next; q->next=p; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

This code for:

1) Add five integer values into a queue.

2) Delete the values from the queue then store the popped values in a sorted linked list and print it on the screen

I need details comments for each line ... Thank you.

The code: (Programming Language is C):

#define MAXELEMENTS 5

#define MIN 0

struct queue {

int items[MAXELEMENTS];

int front, rear;

};

struct node {

int data;

struct node *next;

};

typedef struct node *NODEPTR;

void cqinsert(struct queue*,int);

int cqdelete(struct queue*);

void insert(node *head,int);

int main(void) {

struct queue q;

int x;

q.front= q.rear=-1;

for(int i=0;i<5;i++)

{ printf("Enter input Number \n");

scanf("%d",&x);

cqinsert(&q,x);

}

x=cqdelete(&q);

NODEPTR head=(NODEPTR)malloc(sizeof(struct node));

head->data=x;

head->next=NULL;

for(int i=0;i<5;i++)

{ x=cqdelete (&q);

insert(head, x);

}

NODEPTR save = head;

do { printf("%d\n",save->data);

save-save->next;

} while(save!=NULL);

return 0;

}//end of main

int cqdelete(struct queue *pq)

{ if(pq->front==-1)

{ printf("\nQueue Underflow");

exit(1);

}

int pq->items[pq->front];

if(pq->front==pq->rear)/*queue has only one

element*/

{ pq->front =-1;

pq->rear =-1;

}

else

if(pq->==MAXELEMENTS-1)

pq->front=0;

else

pq->front=pq->front+1;

return(item);

}

void cqinsert(struct queue *pq,int x)

{

if((pq->front==0 && pq->rear==MAXELEMENTS-1)||(front==pq->rear+1))

{

printf("\nQueue Overflow \n");

//exit(0);

return;

}

if(pq->front==-1) /*queue is empty*/

{

pq->front=MIN;

pq->rear=MIN;

}

else

if(pq->rear==MAXELEMENTS-1) /*rear is at last position of queue*/

pq->rear=0;

else

pq->rear=pq->rear+1;

pq->items[rear]=x;

}

void insert(node*head,int x){

NODEPTR p,q;

q=NULL;

for(p=head:p!=NULL && x>p->data;p+p->next)

q=p;

if(q==NULL) /*insert x at the head of the list*/

{

p=(NODEPTR)malloc(sizeof(struct node));

p->data=x;

p->next=head;

head=p;

}

else{

p=(NODEPTR)malloc(sizeof(struct node));

p->data=x;

p->next=q->next;

q->next=p;

}

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education