ITPub博客

首页 > 应用开发 > > c++的引用不知道为什么会报错?求指教!

c++的引用不知道为什么会报错?求指教!

作者:zhjhome 时间:2019-11-21 15:22:34 0 删除 编辑
#include <iostream>
#include <cstdio>
using namespace std;
typedef int ElemType;
typedef int Status;
const int n=5;
struct Node{
    ElemType data;
    struct Node *next;
}Node,*LinkList;
void print_title();
void CreateList(LinkList &L,int n);
Status ListDelete_first(LinkList &L);
Status ListTraverse(LinkList &L);
int main(){
    int x;
    ElemType e;
    LinkList L;
    CreateList(L,n);
    print_title();
    scanf("%d",&x);
    switch(x){
            case 1:ListDelete_first(L);break;
            case 2:ListTraverse(L);break;
            default:;
    }
    return 0;
}
void print_title(){
    cout<<"Delete a number in the first,input 1;"<<endl;
    cout<<"See all numbers,input 2;"<<endl;
    cout<<"Quit,input any other characters."<<endl;
}
void CreateList(LinkList &L,int n){
    LinkList p;
    L=(LinkList)malloc(sizeof(Node));
    L->next=NULL;
    for(i=n;i>0;--i){
        p=(LinkList)malloc(sizeof(Node));
        cin>>p->data;
        p->next=L->next;
        L->next=p;
    }
}
Status  ListDelete_first(LinkList &L){
    LinkList p;
    p=L->next;
    if(!p)return false;
    p=p->next;
    L->next=L->next->next;
    free(p);
    p=NULL;
    return true;
}
Status  ListTraverse(LinkList &L){
    LinkList p;
    p=L->next;
    if(!p){
        cout<<"empty list!"<<endl;
        return false;
    }
    while(p->next){
        p=p->next;
        cout<<p->data<<"\t";
    }
    cout<<endl;
    return true;
}
//error: variable or field 'CreateList' declared void|
//error: 'L' was not declared in this scope|
//error: expected primary-expression before 'int'|


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2530/viewspace-3167334/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 函数的返回值
请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    102
  • 访问量
    951