首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

热心人帮小弟我看看这个程序哪错了

2012-03-09 
热心人帮我看看这个程序哪错了!#include stdio.h #defineNULL0#defineMAX100structqueue*QstructNode{i

热心人帮我看看这个程序哪错了!
#include "stdio.h "
#define   NULL   0
#define   MAX   100
struct   queue   *Q;
struct   Node
{   int   data;
    struct   Node   *lchild,*rchild;
};

typedef   struct   Node   ElemType;

struct   list
{   ElemType   *data;
    struct   list   *next;
};

struct   queue
{   struct   list   *front,*rear;
    int   count;
};

struct   queue   push(ElemType   node)
{   struct   list   *pnew,*p1,*p2;
    pnew-> data=node-> data;
    pnew-> next=NULL;
    if(Q-> count==0)       Q-> front=pnew;
    else       {   for(p1=Q-> rear;p1-> next!=NULL;)
        {   p2=p1;p1=p1-> next;}
    if(p1==Q-> rear)       Q-> rear=pnew;
    else   p1-> next=pnew;
    }
    Q-> count++;
    return   Q;
}

ElemType   pop()
{     struct   list   pDel;
      ElemType   temp;
      if(Q-> count==1)       Q-> rear   =NULL;
      pDel=Q-> front;
      temp=pDel-> data;
      Q-> front=Q-> rear;
      Q-> rear=Q-> rear-> next;
      Q-> count--;
      delete   pDel;
      pDel=NULL;
      return   temp;
}

ElemType   *creatnode()
{   ElemType   *pnode;
    pnode=(ElemType   *)malloc(sizeof(ElemType));
    scanf( "%d ",&pnode-> data);
    if(!pnode-> data)         pnode=NULL;
    return   pnode;
}

ElemType   *creatTree(ElemType   *head)
{   head=creatnode();
      if(head)
              {head-> lchild=creatTree(head-> lchild);
  head-> rchild=creatTree(head-> rchild);
}
      return(head);
}

void   printTree(ElemType   head)
{       while   (head!=   NULL)
              {   print( "%d ",head-> data);
if   (head-> lchild!=   NULL)
      Q   =push   (Q,   head-> lchild);
if   (head-> rchild!=   NULL)
      Q   =   push(Q,   head-> rchild);
if   (Q-> count   !=   0)
      printTree(pop(Q),Q);
else       return;
              }
}

void   initi()
{     Q-> front=Q-> rear=NULL;
      a-> count=0;
}

main()
{   ElemType   *boot=NULL;
    initi();
      boot=creatTree(boot);
        printTree(boot);
          printf( "\n ");
              getch();
}


那位好心人帮忙看看这个程序应该怎么写?为什么有好多错?好心人帮忙改改!

[解决办法]
Compiling...
Cpp1.cpp
E:\Cpp1.cpp(24) : error C2819: type 'Node ' does not have an overloaded member 'operator -> '
E:\Cpp1.cpp(6) : see declaration of 'Node '
E:\Cpp1.cpp(24) : error C2227: left of '-> data ' must point to class/struct/union
E:\Cpp1.cpp(33) : error C2440: 'return ' : cannot convert from 'struct queue * ' to 'struct queue '
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\Cpp1.cpp(40) : error C2679: binary '= ' : no operator defined which takes a right-hand operand of type 'struct list * ' (or there is no acceptable conversion)
E:\Cpp1.cpp(41) : error C2819: type 'list ' does not have an overloaded member 'operator -> '
E:\Cpp1.cpp(13) : see declaration of 'list '
E:\Cpp1.cpp(41) : error C2227: left of '-> data ' must point to class/struct/union
E:\Cpp1.cpp(45) : error C2440: 'delete ' : cannot convert from 'struct list ' to ' '
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\Cpp1.cpp(45) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
-----------------------------------------------
1.pnew-> data=node-> data;//这里的node不是指针,错误提示没有重载-> ,改成node.data后发现,pnew-> data竟然是个指针,不知道你原意是想干什么
2.return Q;返回的类型跟函数定义的类型不一样
3.pDel=Q-> front;右值未知,应该是因为前面的返回类型错误造成的
4.又一个-> 的错,如果是指针才用-> ,不然用.
5.由于返回错误造成了一系列的错误
6.: error C2227: left of '-> data ' must point to class/struct/union//-> data必须指向class/struct/union
7.你在哪里看到的delete,没学会就用........,delete只能用来释放用new申请的内存空间


总结,如果是学C的,再巩固下语法,如果是学C++,重头看吧,看样子现在是研究数据结构,但是你的基本语法好多不过关啊

热点排行