Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the definition of the function moveNthFront that takes as a parameter a po

ID: 3683246 • Letter: W

Question

Write the definition of the function moveNthFront that takes as a parameter a positive integer, n. The function moves the nth element of the queue to the front. The order of the remaining elements remains unchanged. For example, suppose: queue = {5, 11, 34, 67, 43, 55} and n = 3. After a call to the function moveNthFront: queue = {34, 5, 11, 67, 43, 55}. Add this function to the class queueType. Also, write a program to test your method.

This program needs file names called:

queueADT.h

queueAsArray.h

intmain.cpp

Explanation / Answer

#include<iostream.h>
#include<conio.h>

class queueType
{
public:
   void moveNthFront(int n)
   {
       int q[]={5,11,34,67,43,55},i,a[6];
       int aa;
       for(i=0;i<6;i++)
       {
           aa=q[n-1];
           for(i=0;i<6;i++)
           {
               if(q[i]!=q[n])
                   a[i+1]=q[i];
           }
           a[0]=aa;
       }

       for(i=0;i<6;i++)
       {
           cout<<a[i]<<", ";
       }
   }
};

void main()
{
   int n;
   queueType o;
   cout<<"enter number of index to move front";
   cin>>n;
   o.moveNthFront(n);
   getch();
}