请各位帮我看看那里类型不匹配要怎么改~~拜谢了~
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<malloc.h> typedef int TElemType;
typedef struct BitNode
{
TElemType data;
struct BitNode *lchild,*rchild;
}BitNode,*BitTree; #define INITSIZE 100
typedef struct
{
BitTree *top;
BitTree *base;
int stacksize;
}sqstack; void InitStack(sqstack S)
{
S.base = (BitTree *)malloc(INITSIZE * sizeof(BitTree));
if (!S.base)
{
printf("OVERFLOW");
exit(1);
}
S.top = S.base;
S.stacksize = INITSIZE;
} int gettop(sqstack S,BitTree *e)
{
if(S.top==0)
return 0;
*e = *(S.top);
return 1;
} int push(sqstack *S,BitTree *x)
{
if((S->top-S->base)>=S->stacksize)
{
S->base=(BitTree *)realloc(S->base,(S->stacksize+1)*sizeof(BitTree));
if(!S->base)
return 0;
S->stacksize++;
}
S->top++;
*(S->top) = *x;
return 1;
} int pop(sqstack *S,BitTree *e)
{
if(S->top==S->base)
return 0;
*e = *(S->top);
(S->top)--;
return 1;
} int EmptyStack(sqstack *S)
{
if(S->top==S->base)
return 1;
else
return 0;
}
BitTree CreateBitTree(void)
{
BitTree T;
TElemType x;
scanf("%d",&x);
if(x==-1)
T=NULL;
else
{
T=(BitTree)malloc(sizeof(BitNode));
T->data =x;
T->lchild =CreateBitTree();
T->rchild =CreateBitTree();
}
return T;
} void PreOrderBitTree(BitTree T)
{
sqstack S;
BitTree p;
InitStack(S); // 初始化一个栈
push(S,T); // 跟指针结点进栈
while(!EmptyStack(S)) // 栈空时算法结束
{
p=pop(S,p); // 弹栈,p指向(子树)根结点
while(p)
{
printf("%d",p->data ); // 访问根结点
if(p->rchild)
push(S,p->rchild ); // 非空的右指针进栈
p=p->lchild; // 沿着做指针访问,直到做指针为空
}
}
} void InOrderBitTree(BitTree T)
{
sqstack S;
BitTree p;
InitStack(S); // 初始化一个栈
p=T; // p指向根结点
while(p||!EmptyStack(S)) // 当p为空且栈为空的时候结束算法
{
while(p)
{
push(S,p);
p=p->lchild; // 沿左指针走,沿途经过的(子树)根结点指针进栈
}
p=pop(S,p);
printf("%4d",p->data ); // 当左指针为空时弹栈并访问该结点(子树根结点)
p=p->rchild ; // 向右跳一步到右子树上继续进行遍历过程
}
} void PostOrderBitTree(BitTree T)
{
sqstack S;
BitTree p,q;
InitStack(S);
p=T;
q=NULL;
while(p||!EmptyStack(S))
{
if(p!=q)
{
while(p)
{
push(S,p); // p非空,压栈
if(p->lchild)
p=p->lchild; // 沿左指针下移,若左指针为空
else
p=p->rchild; // 沿右指针下移
}
}
if(EmptyStack(S)) break; // 若栈空,则结束
q=gettop(S,p);
if(q->rchild==p) // 若q的右指针为空(p为空)或指向刚刚访问过的结点
{
p=pop(S,p); // 则弹栈,并访问该结点
printf("%4d",p->data);
}
else p=q->rchild; // 否则,沿q的右指针继续遍历访问
}
} void main()
{
BitTree T=NULL;
char choice;
T=CreateBitTree();
printf("1.先序遍历\n");
printf("2.中序遍历\n");
printf("3.后序遍历\n");
printf("4.退出\n");
printf("\nplease choice:");
while(1)
{
scanf("%c",&choice);
switch(choice)
{
case'1':
printf("先序非递归遍历\n");
PreOrderBitTree(T);
printf("\nplease choice:");
break;
case'2':
printf("中序非递归遍历\n");
InOrderBitTree(T);
printf("\nplease choice:");
break;
case'3':
printf("后序非递归遍历\n");
PostOrderBitTree(T);
printf("\nplease choice:");
break;
case'4':
printf("Exit!");
exit(1);
break;
}
}
getch();
} D:\Program Files\Microsoft Visual Studio\MyProjects\3\3.cpp(95) : error C2664: 'push' : cannot convert parameter 1 from 'sqstack' to 'sqstack *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\Program Files\Microsoft Visual Studio\MyProjects\3\3.cpp(96) : error C2664: 'EmptyStack' : cannot convert parameter 1 from 'sqstack' to 'sqstack *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\Program Files\Microsoft Visual Studio\MyProjects\3\3.cpp(96) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe. 3.exe - 3 error(s), 0 warning(s)