- 1
Implement queue in c program and implement sort function for queue elements in queue in descending any library function cannot
Use
6 RĂ©ponses
+ 2
Any code you have written so far ?
0
I write implement queue using arrays in c
But how to sort a elements already in a queue is difficult to me
0
Can you give me some solution
0
#include<stdio.h>
Int front=0,rear=-1;
Int queue[];
Void insert(int);
Void delete();
Void display();
Int main()
{
Int choice,value;
While(1)
{
Printf(âEnter choice:â);
Printf(â1.insert \nâ);
Printf(â2.Delete\nâ)
Printf(3.display\nâ);
Printf(4.Exit\nâ);
Scanf(â%dâ,&choice);
Switch(choice)
{
Case 1:
Printf(âEnter a the value to insert:\nâ);
Scanf(â%dâ,&value);
Insert(value);
Break;
Case 2:
Delete();
Break;
Case 3:
Display();
Break;
Case 4:
Return 0;
Default:
Printf(âPlease enter correct choice\nâ);
}
}
}Void insert(int value)
{
If(Rear>=4)
{
Printf(âQueue is full\nâ);
Return ;
}
Rear++;
Queue[rear]=value;
}
Void delete()
{
If(Rear==-1||front>rear)
{
Printf(âQueue is empty\nâ);
Front =0;
Rear=-1;
Return ;
}
Printf(â%d\nâ,queue[front]);
Front ++;
}
Void insert(int value)
{
If(Rear>=4)
{
Printf(âQueue is full\nâ);
Return ;
}
Rear++;
Queue[rear]=value;
}
Void delete()
{
If(Rear==-1||front>rear)
{
Printf(âQueue is empty\nâ);
Front =0;
Rear=-1;
0
Rear=-1;
Return ;
}
Printf(â%d\nâ,queue[front]);
Front ++;
}
Void display()
nt;
If(front>rear || rear==-1)
{
Printf(âqueue is empty\nâ);
Return ;
}
While(temp!=(rear+1))
{
Printf(â%d\nâ,queue[temp]);
Temp++;
}
}
0
This is my code
Can you please how to do a user defined function for sort a elements in descending order for an queue elements in c language