write a function to insert an element in the middle of a queue. Please use C++ and make sure its a function. Thanks
#include <stdio.h>
#define MAX 100
void enqueue(int a);
void insert_middle(int a); // insert the lement into the middle
function
void display();
int queue[MAX];
int rear = -1;
int front = -1;
int main()
{
enqueue(1);
enqueue(2);
enqueue(3);
enqueue(4);
printf("Before inserting the element 5 into the middle :
\n");
display();
insert_middle(5);
printf("After inserting the element 5 into the middle : \n");
display();
}
void enqueue(int a)
{
if(rear == MAX - 1)
{
printf("overflow"); // if it reaches to the maximm limit
}
else
{
if(front == - 1)
{
front = 0;
}
rear++;
queue[rear] = a;
}
}
void insert_middle(int a) // function for inserting the lement
into the middle of the queue
{
int i;
for(i = rear; i >= (rear + 1) / 2; i--) // move the element for
the second half to the consecutive locations
{
queue[i + 1] = queue[i];
}
queue[(rear + 1) / 2] = a; // place the value into the middle
rear++;
}
void display()
{
for(int i = front; i <= rear; i++) // displaying the elements in
the queue format
{
printf("%d ", queue[i]);
}
printf("\n");
}
OUTPUT :
write a function to insert an element in the middle of a queue. Please use C++...
Please write in c++ language: -Create a queue -Insert elements {1, 2, 3, 4, 5} -Print alternate numbers from queue
For my assignment, I'm trying to write Insert function like C++ insert. My function should insert one string into other string at a certain position. Inputs: destination : Be my friend today source : good position : 6 Output: Be my good friend today How should I make room in the middle of the string ? This is my code so far. Insert PROC PROC uses edi esi ebx ecx, destination:DWORD , source:DWORD, position:DWORD mov esi,destination ;add esi address...
Write a defining table and a function that returns the value of the middle element in an array. If the array has an even number of elements, then this function must return the average of the two middle elements. The function must have this header: function getMiddle(list)
void firstNode Write a function in c++ to insert element after P Activate Windos Go totivate Windows
Write only function. In c++ 3. a) Write a function, to be included in a queue class - circular array implementation (20 p that will print all the items in the queue from front to rear
C++ ((USE STL verison please)) Implement the queue class as shown above. Use your queue to store the names of 5 students waiting outside Student Services to meet with advisors. You may want to add more data to each node including student ID, Major, etc. Add a member function displayQueue which displays the contents of the queue. Write the main function to test the queue. CLASS: #ifdef queue_h #define queue_h namespace queues { struct queueNode{ char data; queueNode *link; };...
Given a 5 element queue Q (from front to back: a, x, t, c, z), and an empty stack S, remove the elements one-by-one from Q and insert them into S, then remove them one-by-one from S and re-insert them into Q. Write down the content of the Q from front to back:
C++ Program: Check if queue is rotation. [32] Write a function bool isRotation(Queue *p, Queue *q) to tell if p is a rotation of q. The integrity of the queues should be maintained on return of the function.
(C++) (VISUAL STUDIO) Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. In a normal Queue, we can insert elements until queue becomes full. But once queue becomes full, we cannot insert the next element even if there is a space in front of queue. Efficiently implement a queue class using a circular...
Please slove all these questions in C language Write a function insert At Position N () for a singly-linked list that has the following declaration and precondition: int insert At Position N (strict node **p Head, int n, int new Data); Precondition: n > 0 and the list always has enough nodes to satisfy the position specified by n. The function should allocate memory for a new node, and initialize it with the new Data value. It should then insert...