#include <iostream>
using namespace std;
typedef int Elem;
typedef struct LNode{
Elem data;
struct LNode* next;
}LNode,*LinkList;
void Init_LinkList(LinkList &L){
LNode *node = new LNode;
node->data = 0;
node->next=NULL;
L = node;
}
int Length(LinkList L){
int len = 0;
LNode *current = L->next;
while (current){
len++;
current=current->next;
}
return len;
}
void head_insert_LinkList(LinkList &L){
for (int i = 0; i < 10; ++i) {
Elem e;
LNode *node = new LNode ();
cin>>e;
node->data = e;
node->next = L->next;
L->next=node;
L->data+=1;
}
}
void tail_insert_LinkList(LinkList &L){
LNode *tail=L;
for (int i = 0; i < 10; ++i) {
Elem e;
LNode *node = new LNode ();
cin>>e;
node->data = e;
node->next = NULL;
tail->next = node;
tail = node;
L->data+=1;
}
}
void print_LinkList(LinkList L){
LNode *current = L->next;
while (current){
cout<<current->data<<" ";
current = current->next;
}
cout<<endl;
}
LNode *getElem(LinkList L,int i){
int j=1;
LNode *current = L->next;
if (i==0)return L;
if (i<0)return NULL;
while (current&&j<i){
current=current->next;
j++;
}
return current;
}
LNode *LocateElem(LinkList L,Elem e){
LNode *current = L->next;
while(current && current->data!=e){
current = current->next;
}
return current;
}
void Insert_LinkList_head(LinkList &L,int pos,Elem e){
LNode *node = new LNode;
node->data = e;
LNode *prior = getElem(L,pos-1);
if (!prior)return;
node->next = prior->next;
prior->next = node;
}
void Insert_LinkList_tail(LinkList &L,int pos,Elem e){
LNode *node = new LNode;
node->data = e;
LNode *prior = getElem(L,pos);
if (!prior)return;
node->next = prior->next;
prior->next = node;
}
void delete_LinkList(LinkList &L,int pos){
LNode *prior = getElem(L,pos-1);
if (!prior){
return;}
LNode *q = prior->next;
prior->next = q->next;
delete q;
}
int main(){
LinkList L1,L2,L3;
Init_LinkList(L1);
Init_LinkList(L2);
Init_LinkList(L3);
head_insert_LinkList(L1);
int len = Length(L1);
cout<<"L1的长度:"<<len<<endl;
Insert_LinkList_tail(L1,5,16);
delete_LinkList(L1,2);
print_LinkList(L1);
tail_insert_LinkList(L2);
len = Length(L2);
cout<<"L2的长度:"<<len<<endl;
Insert_LinkList_head(L2,5,16);
delete_LinkList(L2,2);
print_LinkList(L2);
}