连接两个链表
来源:互联网 发布:新网域名购买 编辑:程序博客网 时间:2024/05/08 17:12
程序源代码:
#include "stdlib.h"
#include "stdio.h"
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
link delete_node(link pointer,link tmp)
{if (tmp==NULL) /*delete first node*/
return pointer->next;
else
{ if(tmp->next->next==NULL)/*delete last node*/
tmp->next=NULL;
else /*delete the other node*/
tmp->next=tmp->next->next;
return pointer;
}
}
void selection_sort(link pointer,int num)
{ link tmp,btmp;
int i,min;
for(i=0;i<num;i++)
{
tmp=pointer;
min=tmp->data;
btmp=NULL;
while(tmp->next)
{ if(min>tmp->next->data)
{min=tmp->next->data;
btmp=tmp;
}
tmp=tmp->next;
}
printf("\40: %d\n",min);
pointer=delete_node(pointer,btmp);
}
}
link create_list(int array[],int num)
{ link tmp1,tmp2,pointer;
int i;
pointer=(link)malloc(sizeof(node));
pointer->data=array[0];
tmp1=pointer;
for(i=1;i<num;i++)
{ tmp2=(link)malloc(sizeof(node));
tmp2->next=NULL;
tmp2->data=array[i];
tmp1->next=tmp2;
tmp1=tmp1->next;
}
return pointer;
}
link concatenate(link pointer1,link pointer2)
{ link tmp;
tmp=pointer1;
while(tmp->next)
tmp=tmp->next;
tmp->next=pointer2;
return pointer1;
}
void main(void)
{ int arr1[]={3,12,8,9,11};
link ptr;
ptr=create_list(arr1,5);
selection_sort(ptr,5);
}
#include "stdlib.h"
#include "stdio.h"
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
link delete_node(link pointer,link tmp)
{if (tmp==NULL) /*delete first node*/
return pointer->next;
else
{ if(tmp->next->next==NULL)/*delete last node*/
tmp->next=NULL;
else /*delete the other node*/
tmp->next=tmp->next->next;
return pointer;
}
}
void selection_sort(link pointer,int num)
{ link tmp,btmp;
int i,min;
for(i=0;i<num;i++)
{
tmp=pointer;
min=tmp->data;
btmp=NULL;
while(tmp->next)
{ if(min>tmp->next->data)
{min=tmp->next->data;
btmp=tmp;
}
tmp=tmp->next;
}
printf("\40: %d\n",min);
pointer=delete_node(pointer,btmp);
}
}
link create_list(int array[],int num)
{ link tmp1,tmp2,pointer;
int i;
pointer=(link)malloc(sizeof(node));
pointer->data=array[0];
tmp1=pointer;
for(i=1;i<num;i++)
{ tmp2=(link)malloc(sizeof(node));
tmp2->next=NULL;
tmp2->data=array[i];
tmp1->next=tmp2;
tmp1=tmp1->next;
}
return pointer;
}
link concatenate(link pointer1,link pointer2)
{ link tmp;
tmp=pointer1;
while(tmp->next)
tmp=tmp->next;
tmp->next=pointer2;
return pointer1;
}
void main(void)
{ int arr1[]={3,12,8,9,11};
link ptr;
ptr=create_list(arr1,5);
selection_sort(ptr,5);
}
- 连接两个链表
- 连接两个排序的链表
- 连接两个链表的实现
- 两个单循环链表的连接
- 连接两个DataTable表
- 连接两个表查询数据
- 由“两个链表的连接”思考C
- 连接两个单向链表,返回排序后的结果。
- 【数据结构】两个单循环链表的连接操作
- 运用递归将两个链表进行连接
- oracle两个表连接的分段查询
- 两个表左连接取数只取一行
- 两个表指定条件的笛卡尔连接
- LeetCode 21 Merge Two Sorted Lists 把两个链表有序连接
- 第四周项目三(2) 两个链表的连接
- 第四周项目三(2)两个链表的连接
- 第四周项目—3(2)连接两个链表
- 连接两个C_style字符串
- 创建一个链表
- about hashtags of tweet
- 反向输出一个链表
- 使用Aspectj进行AOP开发
- 宽字符和窄字符的转换接口
- 连接两个链表
- tcpdump简介
- 八进制转换为十进制
- 全排列之探索最简洁写法
- JQuery---右键菜单版本一
- 有关Java包装类及其拆箱装箱的小结
- 【C/C++】编程常用命名方法
- BUG:8993720
- Linux下TCP/UDP socket服务器模型