Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include "Queue.h"
#include<stack>
#include<iostream>
using namespace std;
int main() {

	int number;
	int size;
	cout << "Enter size of queue"; 
	cin >> size;
	Queue q1(size);
	stack<int>stk;

	for (int i = 0; i < size; i++) {
		cout << "Enter series of number \n";
		cin >> number;
		q1.enque(number);
		stk.push(number);
	}

	cout << "The correct order is \n";
	q1.display();
	cout << "The reversed order is ";
	while (stk.empty()==false) {
       stk.top();
		stk.pop();
	}

	return 0;
}


void Queue::display() {
	cout << "All value of queue are";
	if (!isEmpty()) {
		for (int i = front; i <= rear;i++) {
			cout << arr[i];

		}
		cout << endl;
	}
}


What I have tried:

I have a problem in display function as it print out garbage value I do not know why??
for instance it is queue implementation I have implemeneted it using array in class with header and cpp file but I have uploaded the code of the main and display fucntion
I have copied code of display function from cpp file just for view
If anyone know a solution it will be apperciated.
Posted
Updated 10-Mar-23 7:51am
v2
Comments
jeron1 10-Mar-23 13:33pm    
You're probably going to have to add the implementation of the queue class to the original post, use the green 'Improve question' option.

1 solution

Quote:
I have copied code of display function from cpp file just for view

You need to learn extremly quickly the variables are the glue between different parts of a program.
First, you store data in q1 and stk, then you try to display the data by using arr. How do you think, the program will make the link between those variable ?
Where is the magic that move the data between variables?
 
Share this answer
 
v2
Comments
Noran Azab 10-Mar-23 13:54pm    
this is not the problem for sure I have declared variable arr but I did not upload the full implmentation.
Patrice T 10-Mar-23 15:39pm    
Try to build a shorter implementation for this problem.
Nobody will guess what you didn't shown us.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900