Question

Given an integer k and a queue of integers, we need to reverse the order of...

Given an integer k and a queue of integers, we need to reverse the order of the first k elements.without including stacks or queus as a library in c++

submit:

A header file containing the definition of the Queue class,

C++ file contains the implementation of the functions

C++file contains the main function to test the class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>
using namespace std;
void reverse(int a[20],int k,int p)
{ for(int i=0,j=k-1;i<=j;i++,j--)
{int t=a[i];
a[i]=a[j];
a[j]=t;}
cout<<"Array with reverse elements is"<<endl;
for(int i=0;i<p;i++)
cout<<a[i]<<" ";
}

int main()
{int k;int a[20];int p;int i;
cout<<"Enter the integer k"<<endl;
cin>>k;
cout<<"enter the no of elements in array"<<endl;
cin>>p;
cout<<"Enter the elements of queue"<<endl;
for(i=0;i<p;i++)
cin>>a[i];
reverse(a,k,p);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Given an integer k and a queue of integers, we need to reverse the order of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a method called reverseFirstK that accepts an integer k and a queue of integers as...

    Write a method called reverseFirstK that accepts an integer k and a queue of integers as parameters and reverses the order of the first k elements of the queue, leaving the other elements in the same relative order. For example, if a queue named q stores [10, 20 30, 40, 50, 60, 70, 80, 90], the call of reverseFirstK (4, q):should change the queue to store [40, 30 20, 10, 50, 60, 70, 80, 90]. If k is 0 or...

  • You are a senior team lead for a fledgling software engineering firm. In order to meet...

    You are a senior team lead for a fledgling software engineering firm. In order to meet a tight deadline, you have hired a freelance programmer to remotely assist you and your small team. To ensure that this freelancer can deliver usable code, you ask them to submit a simple header file named test.h that contains a definition for a class named Test. You specify that this Test class must contain one private, bool-typed member variable named b and a corresponding...

  • Write a program to convert an expression written in infix notation to be converted to postfix...

    Write a program to convert an expression written in infix notation to be converted to postfix notation. The program must do the following: a. Read a string of characters representing an expression in infix notation. The '$' is to be added at the end of the string to mark its ending. Each character is a letter, digit, +,-,*, or /. If a character is any other character an error must be signaled and the program is terminated b. Use stacks...

  • Using java Create a simple queue class and a simple stack class. The queue and stack...

    Using java Create a simple queue class and a simple stack class. The queue and stack should be implemented as a linked list. Create three functions that utilize these data structures Write a function that opens a text file and reads its contents into a stack of characters. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse...

  • CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class....

    CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end. class queue : private unorderedArrayListType { public: bool isEmpty() const; // test whether queue is empty // Post: returns true if queue is...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • Write a C++ program to implement Queue ADT using singly linked structure. The program includes the...

    Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...

  • C++ A rational number is of the form a/b, where a and b are integers, and...

    C++ A rational number is of the form a/b, where a and b are integers, and b is not equal 0. Develop and test a class for processing rational numbers. Details: Your program should have 3 files: a driver file to test the operations, a header file for the class definition and any operator overloads you need, and an implementation file with the definitions of the items in the header file. The class should read and display all rational numbers...

  • Skills needed to complete this assignment: template metaprogramming. PROGRAMMING LANGUAGE: C++ PROMPT: Write a template version...

    Skills needed to complete this assignment: template metaprogramming. PROGRAMMING LANGUAGE: C++ PROMPT: Write a template version of a class PQueue that implements a priority queue. A priority queue is a list of items that is always ordered by priority. Each item that is added to the list requires an associated priority value, an integer for this problem, where 0 represents the highest priority and larger values are lower in priority. Removing an item from the queue removes the item with...

  • Q.1. Write a C program that determines whether a line entered by a user is a...

    Q.1. Write a C program that determines whether a line entered by a user is a palindrome or not. You must demonstrate it as an application of stack (you may use linked list implementation demonstrated in the class). Hint! Think of the basic property of a stack i.e. LIFO (list-in-first-out). Q.2. Write a charQueue header file containing all the function headers of following functions: 1- initiateQueue—to initialize a queue 2- enqueue—to add a node at the rear end of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT