
Write the C++ code of queue which is performed multiple task which are given below and performed all task by using Arrays.
N.b array size=ten
i)En-queue values Two,three,four,five,six,seven and eight
ii)De-queue values Two and three
iii)Please create is empty and queue function for telling them queue is empty or full.
iv)Sort all values of queue and print it

#include <iostream>
using namespace std;
int queue[100], n = 10, front = - 1, rear = - 1;
bool isempty()
{
if(front == -1 && rear == -1)
return true;
else
return false;
}
bool isfull()
{
if (rear == n - 1)
return true;
else
return false;
}
void Enqueue(int value)
{
if (isfull())
cout<<"Queue is full"<<endl;
else
{
if (front == - 1)
front = 0;
rear++;
queue[rear] = value;
}
}
void Dequeue()
{
if( isempty() )
cout<<"Queue is empty\n";
else if( front == rear )
front = rear = -1;
else
{
cout<<"Element deleted : "<< queue[front] <<endl;
front++;
}
}
void print()
{
if (isempty())
cout<<"Queue is empty"<<endl;
else
{
cout<<"Queue : ";
for (int i = front; i <= rear; i++)
cout<<queue[i]<<" ";
cout<<endl;
}
}
void sortQueue()
{
//Sorting elements of queue using bubble sort
for (int j = 0; j < (n-1); ++j)
{
for (int i = 0; i < n - (j-1); ++i)
{
if (queue[i] > queue[i + 1])
{
int temp = queue[i];
queue[i] = queue[i + 1];
queue[i + 1] = temp;
}
}
}
}
int main()
{
//Enqueue operations
Enqueue(2);
Enqueue(3);
Enqueue(4);
Enqueue(5);
Enqueue(6);
Enqueue(7);
Enqueue(8);
print();
//Dequeue operations
Dequeue();
Dequeue();
print();
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- 3. Selection Sort• The idea in a selection sort is that you locate the largest item out of a set ofunsorted items, and move it into position at the end of the unsorted items. Asorted region grows one item at a time, while an unsorted region shrinks.• As done in Part 1, fill an array with random numbers.• Write a function that locates the largest element in the portion of the arraybeginning at the start of the array, up to a given index, and swaps the largestitem with the item at the given index.• E.g. If searching a[0] to a[7] locates the largest item at a[4], a[4] and a[7] would beswapped.• Write a second function that calls the first function repeatedly, until the entirearray is sorted. (Each time the first function is called, it will search one fewerelement)arrow_forwardWrite the function lastOf which searches the array a for the last occurance of any value contained in the array b. Returns the index if found. If not found, return -1. arrays.cpp 1 #include 2 int last0f(const int a[], int alen, const int b[], int bLen) { 3 4 5 6 7 8 }arrow_forwardC programarrow_forward
- 1. Display Function Implement a function to display the contents of the patient_list array. Add code to call this function. Note that there are multiple places where this function needs to be called. Look for the // TODO comments to find the correct locations. 2. Sorting the array by Age Implement the code to sort the contents of the patient_list array based on the value stored in the age field. To do this you will need to implement code that relies on the qsort function from the C Standard library A function that compares two patient elements, based on the value stored in the age field. A call to the qsort function, which includes the array to be sorted, the number of elements in the array, the size of each array element and the function used to compare the array elements. Add code to call the qsort function, using the age comparison function that you implemented. This code should be placed just under the appropriate // TODO comment in main(). Sorting the array by…arrow_forward/* (name header) #include // Function declaration int main() { int al[] int a2[] = { 7, 2, 10, 9 }; int a3[] = { 2, 10, 7, 2 }; int a4[] = { 2, 10 }; int a5[] = { 10, 2 }; int a6[] = { 2, 3 }; int a7[] = { 2, 2 }; int a8[] = { 2 }; int a9[] % { 5, 1, б, 1, 9, 9 }; int al0[] = { 7, 6, 8, 5 }; int all[] = { 7, 7, 6, 8, 5, 5, 6 }; int al2[] = { 10, 0 }; { 10, 3, 5, 6 }; %3D std::cout « ((difference (al, 4) « ((difference(a2, 4) <« ((difference (a3, 4) « ((difference(a4, 2) <« ((difference (a5, 2) <« ((difference (a6, 2) <« ((difference (a7, 2) <« ((difference(a8, 1) « ((difference (a9, 6) « ((difference(a10, 4) " <« ((difference(al1, 7) « ((difference (al2, 2) == 10) ? "OK\n" : "X\n"); << "al: << "a2: %3D 7)? "OK" : "X") << std::endl == 8) ? "OK\n" : "X\n") 8) ? "OK\n" : "X\n") == 8) ? "OK\n" : "X\n") == 8) ? "OK\n" : "X\n") == 1) ? "OK\n" : "X\n") == 0) ? "OK\n" : "X\n") 0) ? "OK\n" : "X\n") == 8) ? "OK\n" : "X\n") == 3) ? "OK\n" : "X\n") == 3) ? "OK\n" : "X\n") == << "a3: == << "a4: <<…arrow_forwardAHPA #11: Changing Grades * * Create a C function (switcher) that will receive a pointer to the finalExams array, using only pointers look for D scores and boost them to C scores. (ouput should be same as picture)arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





