链表类:
1.创建带头结点长度为n的链表。
node *creat(int n){//创建带头结点的长度为n的链表
node*head,*p,*s;
head=(node*)malloc(sizeof(node));
head->next=NULL;
p=head;
for(int i=1;i<=n;i++)
{
s=(node*)malloc(sizeof(node));
s->next=NULL;
cin>>s->data;
p->next=s;
p=s;}
return head;}
2.删除链表中指定的元素
node *delect(node*head,int x){//删除值为x的所有元素
node *p=head;
node *s=p->next;
while(s!=NULL){
if(s->data==x){
p->next=s->next;
free(s);
s=p->next;}
else
p=p->next;
s=p->next;}
return head;
}
3.利用冒泡排序进行链表排序。
node*sort(node*h,int n){//n为链表长度,带头节点
node*p,*s;
for(int i=1;i<=n-1;i++){
p=h->next,s=p->next;
while(s!=NULL){
if(p->n>s->n)//需要满足交换的条件
ec(p,s);//交换函数,这里需要自拟。
p=s,s=s->next;
}
}
4.合并两个带头结点的链表。
node*hebing(node *h1,node*h2){
node*p;
p=h1->next;
while(p->next!=NULL)
p=p->next;
p->next=h2->next;
return h1;
}