关于链表的,有一些错误老是解决不了,大家帮忙看看

    技术2022-05-11  19

    #include<stdio.h> /* EOF(=^Z或F6),NULL */#include<process.h> /* exit() */#include<malloc.h>#include<math.h>#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define int ElementTypetypedef int Status; /* Status是函数的类型,其值是函数结果状态代码,如OK等 */typedef int Boolean; /* Boolean是布尔类型,其值是TRUE或FALSE */struct Node;typedef  struct Node *PtrToNode;typedef  PtrToNode List;typedef  PtrToNode Position;struct Node{    ElementType Element;   Position  Next;};

    Position Find( ElementType X, List L ){ Position P; P=L->Next; while( P!=NULL&&P->Element!=X )      P=P->Next; return P;}

    int ListLength(List L) { /* 初始条件:线性表L已存在。操作结果:返回L中数据元素个数 */   int i=0;  List p;p=L->Node;  /* p指向第一个结点 */   while(p) /* 没到表尾 */   {     i++;/* 元素个数加1 */     p=p->next; /* 指针指向下一个元素 */   }   return i; }

    Position FindPrevious( ElementType X, List L ){    Position P;

    /* 1 */   P=L;/* 2 */   while(P->Next !=NULL&& P->Next->Element !=X)/* 3 */       P=P->Next;/* 4 */   return P;}

    int IsLast(Position P, List L ){  return P->Next ==NULL;}

    void Delete(ElementType X, List L ){Position P,TmpCell;P=FindPrevious( X , L );if( !IsLast( P, L ))   /*Assumption of header use */ {                     /* X is found; delete it */    TmpCell=P->Next;//给指针TmpCell赋值    P->Next=TmpCell->Next;//更改P->Next的值    Free(TmpCell);//释放TmpCell所指向的结点  }}

    void  Insert( ElementType X ,Position P ){          Position TmpCell;

    /* 1 */   TmpCell=(Position)malloc( sizeof( struct Node ) );/* 2 */   if(TmpCell == NULL )/* 3 */      printf("Out of space!!!" );

    /* 4 */  TmpCell-> Element =X;/* 5 */   TmpCell->Next=P->Next;/* 6 */   P->Next =TmpCell;         }

    Status ListTraverse(List L){ /* 初始条件:线性表L已存在 */   List p=L-> Element;   while(p)   {     printf("%d ", p-> Element); /* 输出元素 */     p=p->Next; /* 指针指向下一个元素 */   }   printf("/n");   return OK; }

    void main(void)  {List L1;Position P1;int j,x;L1=(List)malloc(sizeof(struct Node)); /* 产生头结点,并使L指向此头结点 */   if(!L1) /* 存储分配失败 */     exit(0);L1->next=NULL; /*头结点的指针域的值为NULL */printf("依次插入元素 33 58 66 76 88 99/n");for(j=1;j<=6;j++){scanf("%d",&x);//通过键盘为x赋值Insert(x, P );//将元素x插入链表中}ListTraverse(L1) ;P1= Find(66, L1 );if(P1)  printf("查找链表元素值为66的元素/n");else printf("没找到/n");Delete(88, L );//删除链表中值为88的元素x=ListLength(L);//调用函数求链表的长度并赋给xprintf("链表表的长度是:%d/n", x);printf("输出链表/n");ListTraverse(L);//调用函数输出整个链表}

     

    错误:链表.cppD:/C++/C存放/链表.cpp(11) : error C2146: syntax error : missing ';' before identifier 'Status'D:/C++/C存放/链表.cpp(11) : fatal error C1004: unexpected end of file found执行 cl.exe 时出错.


    最新回复(0)