Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Please Complete the missing parts of the programC prpgram)

 thank you (1 program and 2 pages)

 

Page 1
The following code implements the following:
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. However, some parts of the code are missing (indicated by
_). Complete the missing parts.
#define
#define
struct queue
{
int items[MAXELEMENTS];
int
};
struct node {
int data;
struct node
};
typedef struct node
void cqinsert(struct queue *, int);
int cqdelete(struct queue *);
void insert(node *head, int);
int main(void) {
struct queue q;
int x;
q.
for (int i = 0; i < 5; i++)
{
= q.rear = -1;
printf("Enter input Number \n");
scanf("%d", &x);
cqinsert(&q, x);
}
X =
(&q);
NODEPTR head = (NODEPTR)malloc(sizeof(struct node));
head->data
= X;
head->next = NULL;
for (int i = 1; i < 5; i++)
{
= cqdelete(&q);
х);
X =
insert(
}
NODEPTR save =
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\n");
{
==
{
exit(1);
}
int item = pq->items[pq->front];
if (pq->front
{
pq->rear) /* queue has only one element */
= -1;
= -1;
%3D
}
Page 4 of 5
expand button
Transcribed Image Text:Page 1 The following code implements the following: 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. However, some parts of the code are missing (indicated by _). Complete the missing parts. #define #define struct queue { int items[MAXELEMENTS]; int }; struct node { int data; struct node }; typedef struct node void cqinsert(struct queue *, int); int cqdelete(struct queue *); void insert(node *head, int); int main(void) { struct queue q; int x; q. for (int i = 0; i < 5; i++) { = q.rear = -1; printf("Enter input Number \n"); scanf("%d", &x); cqinsert(&q, x); } X = (&q); NODEPTR head = (NODEPTR)malloc(sizeof(struct node)); head->data = X; head->next = NULL; for (int i = 1; i < 5; i++) { = cqdelete(&q); х); X = insert( } NODEPTR save = 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\n"); { == { exit(1); } int item = pq->items[pq->front]; if (pq->front { pq->rear) /* queue has only one element */ = -1; = -1; %3D } Page 4 of 5
Page 2
else
if (pq->front
MAXELEMENTS - 1)
==
= 0;
else
= pq->front + 1;
return(item);
}
void cqinsert(struct queue *pq, int x)
0 && pq->rear
|| (pq->front :
if ((pq->front
{
pq->rear + 1))
3%3D
==
==
printf("\nQueue Overflow \n");
llexit(0);
return;
}
if (pq->front
{
-1) /*If queue is empty */
==
pq->front :
pq->rear =
}
else
if (pq->rear :
MAXELEMENTS - 1)/*rear is at last position of queue */
= 0;
==
pq->rear =
else
pq->rear = pq->rear + 1;
pq->items[
}
= x;
void insert(node* head, int x) {
NODEPTR p, q;
q = NULL;
for (p =
;p != NULL && x > p->data; p = p->next)
%3D
q= p;
if (q
{
/* insert x at the head of the list */
p = (NODEPTR)malloc(sizeof(_
p->data = x;
);
%3D
p->next =
head;
= p;
}
else {
p = (NODEPTR)malloc(sizeof(struct node));
p->data = x;
q->next = p;
%3D
}
}
Page 5 of 5
expand button
Transcribed Image Text:Page 2 else if (pq->front MAXELEMENTS - 1) == = 0; else = pq->front + 1; return(item); } void cqinsert(struct queue *pq, int x) 0 && pq->rear || (pq->front : if ((pq->front { pq->rear + 1)) 3%3D == == printf("\nQueue Overflow \n"); llexit(0); return; } if (pq->front { -1) /*If queue is empty */ == pq->front : pq->rear = } else if (pq->rear : MAXELEMENTS - 1)/*rear is at last position of queue */ = 0; == pq->rear = else pq->rear = pq->rear + 1; pq->items[ } = x; void insert(node* head, int x) { NODEPTR p, q; q = NULL; for (p = ;p != NULL && x > p->data; p = p->next) %3D q= p; if (q { /* insert x at the head of the list */ p = (NODEPTR)malloc(sizeof(_ p->data = x; ); %3D p->next = head; = p; } else { p = (NODEPTR)malloc(sizeof(struct node)); p->data = x; q->next = p; %3D } } Page 5 of 5
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education