help me about QUEUE

what wrong with my code??
#include<iostream>
#include<iomanip>
#include<queue>
#include<cstdlib>
using namespace std;
void NhapQueue(queue<char> );
void TachQueue(queue<char>, queue<int>, queue<char>);
void In1(queue<int>);
void In2(queue<char>);
int main()
{
queue<char> Q;
NhapQueue(Q);
queue<int> P1;
queue<char> P2;
TachQueue(Q,P1,P2);
In1(P1);
In2(P2);
return 1;

}
void NhapQueue(queue<char> Q)
{
do{
char c;
cin.get(c);
if(c=='k') break; else Q.push(c);
}while(1);
}
void TachQueue(queue<char> Q, queue<int> P1, queue<char> P2)
{
char *c;
c=new char;
int i=0;
int a;
char x;
do{
x=Q.front();
if(!isalnum(x)) {a=atoi(c);P1.push(a);P2.push(x);c=NULL;} else
{
*(c+i)=x;
}
Q.pop();
cout<<"1"<<endl;
}while(!Q.empty());
}
void In1(queue<int> P1)
{
while(!P1.empty()) {
int c;
c=P1.front();
cout<<c<<endl;
P1.pop();
}
}
void In2(queue<char> P2)
{
while(!P2.empty()) {
char c;
c=P2.front();
cout<<c<<endl;
P2.pop();
}
}
a lot is wrong with it but lets start with
1
2
3
4
5
6
7
8
9
10
11
12
13
void TachQueue(queue<char> Q, queue<int> P1, queue<char> P2)
{
char *c;
c=new char;
int i=0;
int a;
char x;
do{
x=Q.front();
if(!isalnum(x)) {a=atoi(c);P1.push(a);P2.push(x);c=NULL;} else
{
*(c+i)=x;
}

your creating c as a pointer to a char and then you do
a=atoi(c)
without having anything in c
also
*(c+i)=x;
just makes no sense at all i assume you wanted to deference c to get its value and add i to that value which is not whats being done.
your also probably going to want to pass your queues by reference.
also again in TachQueue you are using a do while loop which could be dangerous since you dont know if the queue is empty or not before the loop executes the first time.
and again in main the return should be 0 a return status of 1 usually indicates an error occurred.
Last edited on
thank you. I'll try again.
Topic archived. No new replies allowed.