C++写的链表的基本操作,错误一大堆,又不知道什么原因。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef int ElemType;
typedef int Status;
#define ERROR 0
#define OK 1


typedef struct LNode{
int date;
struct LNode *next;
}LNode,*Linklist;


Status Getelem_L(Linklist L,int i,ElemType &e)
{
    Linklist p;
    p=L;
    int j=0;
    while(j<i&&p)
    {
        p=p->next;
        ++j;
    }
    if(!P||j>i) return ERROR;
   else e=p->date;
    return OK;
}


Status Listinsrt(Linklist &L,int i,ElemType e)
{
    LNode *P=L;
    int j=1;
    while(j<1&&p)
    {
        p=p->next;
        ++j;
    }
    if(!P||j>i) return ERROR;
    else
    {
 LNode *s=(LNode *)malloc(sizeof(LNode));
    s->date=e;
    s->next=p->next;
    p->next=s;
    }
    return OK;




}


Status ListDelet(Linklist &L,int i,int &e)
{




Linklist p,q;
p=L;
int j=0;
while(j<i-1||p)
{
    p=p->next;
    ++j;


}
if(!p||j>i-1) return ERROR;
q=p->next;
e=q->date;
p->next=p->next->next;
free(q);
return OK;
}


void CreateList(Linklist &L,int n)
{
    Linklist p;
    int i;
  L=(LNode *)  malloc(sizeof(LNode));
  L->next=NULL;
    for(i=1;i<=n;++i)
    {
        p=(Linklist) malloc(sizeof(LNode));
        scanf("%d",&p->date);
        p->next=L->next;
        L->next=p;
    }
}


int main()
{
    int n,m,i,a,e,x;
    Linklist L;
    char strInst[30];
    scanf("%d",&n);
    CreateList(L,n);
    printf("\n");
    scanf("%d",&m);
    for(i=1;i<=m;++i)
    {
        printf("/n");
        scanf("%s",&strInst);
        if(strcmp(strInst,"get")==0)
       {scanf("%d",&a);
        Getelem_L(L,a,x);






    }
    else if(strcmp(strInst,"delet")==0)
    {
        scanf("%d",&a);
        ListDelet(L,a,x);
    }
    else if(strcmp(strInst,"insert")==0)
    {
        scanf("%d %d",&a,&e);
        Listinsrt(L,a,e);
    }
}
return OK;
}

错误提示:

.cpp||In function 'Status Getelem_L(LNode*, int, ElemType&)':|
.cpp|24|error: 'P' was not declared in this scope|
.cpp||In function 'Status Listinsrt(LNode*&, int, ElemType)':|
.cpp|33|error: 'p' was not declared in this scope|
.cpp|43|error: 'p' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值