1 2 3 4 5 6 7 8 9 10 11
|
stack(int n)
{
size=n;
data=new char[n];
}
//...
void convert_Postfix()
{
stack(s.size());
//...
}
|
You don't use constructor functions that way. You should change the function to
void allocate(int n)
or something.
Try adding
s1 = "";
before the loop in
convert_Postfix()
90 91 92 93 94
|
else if(precedence())
{
s1+=pop();
push(s[i]);
}
|
I'm not sure, but I think that should be
1 2 3 4 5 6
|
else if(precedence())
{
while(precedence())
s1+=pop();
push(s[i]);
}
|
1 2 3 4
|
~stack()
{
delete[] data;
}
|
Actually, since you only allocate the array inside
convert_Postfix()
and that's basically the only place where you deal with the array or call other functions that deal with the array, maybe you should have
delete[] data;
at the end of that function instead.
Also, why is line 66 there?
for(int i=0;i<size-1;i++)
You're only comparing with
s[0]
so why the need for a loop?
Maybe you should have all the functions private except for
getinfix()
,
showinfix()
, and
showpostfix()
, and have a function call to
convert_Postfix()
at the end of
getinfix()
.