# 链表的使用

//带头结点的单链表，学习之用
#include<iostream>
#include
<string>
usingnamespacestd;

structNode
...{
stringname;
intage;
Node
*next;
}
;

typedefNode

//建立头结点
...{
=newNode;
h
->next=NULL;
returnh;
}

intn)//建立队列链表
...{

h
=initList();
q
=h;

for(inti=0;i<n;i++)
...{
p
=newNode;
cin
>>p->name>>p->age;
q
->next=p;
q
=p;
}

q
->next=NULL;

returnh;
}

...{
p
=h->next;

while(p!=NULL)
...{
cout
<<p->name<<""<<p->age<<endl;
p
=p->next;
}

}

intn)//建立栈链表
...{
h
=initList();
q
=h->next;

for(inti=0;i<n;i++)
...{
p
=newNode;
cin
>>p->name>>p->age;
h
->next=p;
p
->next=q;
q
=p;
}

returnh;
}

...{
returnh==h->next;
}

inti)//查找第i个结点
...{
intk=1;

p
=h->next;
while(k!=i&&p!=NULL)
...{
p
=p->next;
k
++;
}

if(k==i)
returnp;
else
returnNULL;
}

...{

if(i==1||emptyList(h)==true)
...{
p
=h;
}

else
...{
p
=searchIndex(h,i-1);
if(p==NULL)return;
}

s
=newNode;
*s=t;

q
=p->next;
s
->next=q;
p
->next=s;
}

...{

if(i<1||i>n||emptyList(h)==true)return;

if(i==1)
...{
p
=h;
}

else
...{
p
=searchIndex(h,i-1);
}

q
=p->next;
p
->next=q->next;

if(q!=NULL)deleteq;
}

...{
if(emptyList(h)==true)return;

=h->next,q=p->next;
p
->next=NULL;

while(q!=NULL)
...{
p
=q->next;
q
->next=h->next;
h
->next=q;
q
=p;
}

}

voidrun()
...{
intn;
cin
>>n;

//假冒的链表逆置
prtList(h);

//真的链表逆置
reverseList(h);
prtList(h);
*/

//链表的第k个位置插入一个结点
prtList(h);
cout<<endl;

Nodet;
cin>>t.name>>t.age;

intk;
cin>>k;
insertList(h,t,k);
prtList(h);
*/

//链表中删除第k个结点
prtList(h);
cout<<endl;

intk;
cin>>k;
deleteList(h,n,k);
prtList(h);
*/

}

intmain()
...{
inttotal;
cin
>>total;
for(intnow=1;now<=total;now++)run();
return0;
}