init_sqqueue(&Q); en_sqqueue(&Q,t); 调用不了,麻烦帮我改改

[复制链接]
查看11 | 回复2 | 2010-11-30 08:38:59 | 显示全部楼层 |阅读模式
代码在这
init_sqqueue(&Q);
en_sqqueue(&Q,t); 调用不了,麻烦帮我改改
#include
typedef struct node *pointer;
typedef char datatype;
const int maxsize=100;
struct node {
datatype data;
pointer lchild,rchild;
pointer next;
};
typedef pointer bitree;
bitree prein_creat(datatype Pre[],int ps, int pe, datatype In[],int is, int ie){

//先序和中序建立二叉树,ps、pe、is、ie分别为区间的起止节点
bitree t;
int i;
if(ps>pe) return NULL;
t=new node;//生成根结点
t->data=Pre[ps];
i=is;
while(In!=Pre[ps]) i++;//寻找中序序列中根的位置i
//生成左子树
t->lchild=

prein_creat(Pre,ps+1,ps+i-is,In,is,i-1);
//生成右子树
t->rchild=

prein_creat(Pre,ps+i-is+1,pe,In,i+1,ie);
return t;
}
typedef struct {
datatype data[maxsize];
char front,rear;
}sqqueue ;
void init_sqqueue(sqqueue *sq) {
sq->front=sq->rear=0;
}
int empty_sqqueue(sqqueue *sq) {
if(sq->rear==sq->front) return 1;
else return 0;
}
int gethead_sqqueue(sqqueue *sq,datatype x) {
if(sq->rear==sq->front)
{coutdata[(sq->front+1)%maxsize];

return 1;} }
int en_sqqueue(sqqueue *sq,datatype x) {
if((sq->rear+1)%maxsize==sq->front)

{coutrear=(sq->rear+1)%maxsize;

sq->data[sq->rear]=x;

return 1;} }
int de_sqqueue(sqqueue *sq,datatype x) {
if(sq->rear==sq->front)

{coutfront=(sq->front+1)%maxsize;

x=sq->data[sq->front];

return 1;} }
void levelorder(bitree t) { //层次遍历

typedef pointer sqqueue;
pointer p;
node* Q;//循环队列,元素为结点指针,类型为pointer
if(t==NULL) return;
init_sqqueue(&Q);
en_sqqueue(&Q,t); //根结点入队
while(!empty_sqqueue(&Q)) { //队列非空时

de_sqqueue(&Q,p);
coutdatalchild!=NULL)
en_sqqueue(&Q,p->lchild); //左孩子入队

if(p->rchild!=NULL)
en_sqqueue(&Q,p->rchild); //右孩子入队
}
}
好心人 快帮我一下

回复

使用道具 举报

千问 | 2010-11-30 08:38:59 | 显示全部楼层
你犯了明显的错误就是在定义循环队列结构体的时候把front,rear定义成char类型。但是你在后来的调用过程中却把他们当做int型处理。比如说在void init_sqqueue(sqqueue *sq) 中有:
sq->front=sq->rear=0;此时的front = '\t'吧你再去看一下 en_sqqueue(&Q,t)中,你有这样的一句((sq->rear+1)%maxsize==sq->front;这也说明你把front当做int 型处理的。显然肯定会出错的。还有一些小错误:int gethead_sqqueue(sqqueue *sq,datatype x),x改成&x否则会调用丢失的。但是在具体调用的时候你
回复

使用道具 举报

千问 | 2010-11-30 08:38:59 | 显示全部楼层
我试一试. 等高手,这个我也调试不出.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行