#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 ===|