using namespace std;
typedef struct LNode{
int *data;
LNode *next;
}LNode, *Linklist;
bool InitList(LNode &L){
L=(LNode*)malloc(sizeof(LNode));
if(L==NULL)
{
return false;
}
L->next=NULL;
return true;
}
int length(Linklist L){
int len=0;
LNode* p=L;
while(p->next!=NULL){
p=p->next;
len++;
}
return len;
}
LNode* getelem(Linklist L,int i){
LNode* p=L;
int j=0;
while(p!=NULL&&j<i){
p=p->next;
j++;
}
return p;
}
LNode* getelem(Linklist L,int e){
LNode* p=L->next;
while(p!=NULL&&p->data!=e){
p=p->next;
}
return p;
}
bool ListInsertnext(LNode* L,int e){
if(p==NULL)
return false;
LNode* s=(int*)malloc(sizeof(LNode));
if(s==NULL)
return false;
s->data=e;
s->next=p->next;
p->next=s;
return true;
}
bool ListInsert(Linklist& L,int i,int e){
LNode* p=L;
if(i<1)
return false;
int j=0;
while(p!=NULL&&j<i-1){
p=p->next;
j++;
}
return (ListInsertnext(p,e))
}
bool ListInsertPrim(LNode* L,int e){
if(p==NULL)
return false;
LNode* s=(int*)malloc(sizeof(LNode));
if(s==NULL)
return false;
s->next=p->next;
p->next=s;
s->data=p->data;
p->data=e;
return true;
}
bool ListDelete(Linklist& L,int i,int e){
LNode* p=L;
if(i<1)
return false;
int j=0;
while(p!=NULL&&j<i-1){
p=p->next;
j++;
}
if(p==NULL)
return false;
if(p->next==NULL)
return false;
LNode* q=p->next;
e=q->data;
p->next=q-next;
free(q);
return true;
}
Linklist TailInsert(Linklist& L){
int x;
L=(LNode*)malloc(sizeof(LNode))
LNode*s,*r=L;
scanf("%d",&x);
while(x!=9999){
s=(LNode*)malloc(sizeof(LNode));
s->data=x;
r->next=s;
r=s;
scanf("%d",&x);
}
r->next=NULL;
return L;
}
Linklist HeadInsert(Linklist& L){
int x;
L=(LNode*)malloc(sizeof(LNode))
L->next=NULL;
LNode*s;
scanf("%d",&x);
while(x!=9999){
s=(LNode*)malloc(sizeof(LNode));
s->data=x;
s->next=L->next;
L->next=s;
scanf("%d",&x);
}
return L;
}
void ListReverse(Linklist& L){
LNode* s;
LNode *p;
p=L->next;
L->next=NULL;
while(p){
p=p->next;
s=p;
s->next=L->next;
l->next=s;
}
}
void ListReverse(Linklist& L){
LNode* p=NULL;
LNode* s=L->next;
while(s){
LNode* cur=s;
s=s->next;
cur->next=p;
p=cur;
}
}
int main() {
Linklist L;
InitList(L);
return 0;
}