Below is the code for Priority Queue in C using arrays, the code has no errors but the display() function not displaying any element, Please correct if something is wrong: Code: #include #include #define Size 20 struct Queue{ int PQData[Size]; int PQPriority[Size]; }Que; int front=-1; int rear=-1; void InsertQ(int element,int prio){ int i; if(front == 0 && rear == Size-1){ printf("Overflow"); } else { if(front == -1){ front=rear=0; Que.PQData[rear] = element; Que.PQPriority[rear] = prio; } else { if(rear = Size-1) { for (i = front; i < rear; i++) { Que.PQData[i - front] = Que.PQData[i]; Que.PQPriority[i - front] = Que.PQPriority[i]; } rear=rear-front; front=0; } for(i=rear;i>=front;i++){ if(prio>Que.PQPriority[i]){ Que.PQData[i+1] = Que.PQData[i]; Que.PQPriority[i+1] = Que.PQPriority[i]; } } Que.PQData[i+1] = element; Que.PQPriority[i+1]= prio; } } } void DelQ() { if (front == -1) { printf("Queue Empty!!"); } else { printf("Item Deleted %d with priority %d", Que.PQData[front], Que.PQPriority[front]); if (front == rear) { front = rear = -1; } else { front++; } } } void Display() { if (front==-1){ printf("Queue Empty"); } else{ for(int i=front; i
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Below is the code for Priority Queue in C using arrays, the code has no errors but the display() function not displaying any element, Please correct if something is wrong:
Code:
#include <stdio.h>
#include <stdbool.h>
#define Size 20
struct Queue{
int PQData[Size];
int PQPriority[Size];
}Que;
int front=-1;
int rear=-1;
void InsertQ(int element,int prio){
int i;
if(front == 0 && rear == Size-1){
printf("Overflow");
}
else
{
if(front == -1){
front=rear=0;
Que.PQData[rear] = element;
Que.PQPriority[rear] = prio;
}
else {
if(rear = Size-1) {
for (i = front; i < rear; i++) {
Que.PQData[i - front] = Que.PQData[i];
Que.PQPriority[i - front] = Que.PQPriority[i];
}
rear=rear-front;
front=0;
}
for(i=rear;i>=front;i++){
if(prio>Que.PQPriority[i]){
Que.PQData[i+1] = Que.PQData[i];
Que.PQPriority[i+1] = Que.PQPriority[i];
}
}
Que.PQData[i+1] = element;
Que.PQPriority[i+1]= prio;
}
}
}
void DelQ() {
if (front == -1) {
printf("Queue Empty!!");
} else {
printf("Item Deleted %d with priority %d", Que.PQData[front], Que.PQPriority[front]);
if (front == rear) {
front = rear = -1;
} else {
front++;
}
}
}
void Display() {
if (front==-1){
printf("Queue Empty");
}
else{
for(int i=front; i<rear;i++){
printf("Element %d Priority %d",Que.PQData[i],Que.PQPriority[i]);
}
}
}
int main(){
int opt,n,p;
while(true)
{
printf("\n1.Insert the number:\n2.Delete the number:\n3.View:");
scanf("%d",&opt);
if(opt==0)
break;
switch(opt)
{
case 1:
printf("Enter the number to be added: \n");
scanf("%d",&n);
printf("Enter priority of the number \n");
scanf("%d",&p);
InsertQ(n,p);
break;
case 2:
DelQ();
break;
case 3:
Display();
break;
}
}
return 0;
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)