连接两个链表。

#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;

}

int main(void)

{

int arr1[]={3,12,8,9,11};

link ptr;

ptr=create_list(arr1,5);

selection_sort(ptr,5);

}

相关推荐
Johny_Zhao18 分钟前
Docker 一键安装部署 JumpServer 堡垒机
linux·网络安全·信息安全·云计算·shell·jumpserver·ldap·yum源·系统运维
网安小白的进阶之路34 分钟前
A模块 系统与网络安全 第三门课 网络通信原理-3
网络·windows·安全·web安全·系统安全
大熊背2 小时前
图像处理专业书籍以及网络资源总结
人工智能·算法·microsoft
芳草萋萋鹦鹉洲哦8 小时前
【vue3+tauri+rust】如何实现下载文件mac+windows
windows·macos·rust
李洋-蛟龙腾飞公司8 小时前
HarmonyOS NEXT应用元服务常见列表操作多类型列表项场景
windows
物联网老王8 小时前
Ubuntu Linux Cursor 安装与使用一
linux·运维·ubuntu
一位摩羯座DBA10 小时前
Redhat&Centos挂载镜像
linux·运维·centos
学习3人组10 小时前
CentOS配置网络
linux·网络·centos
Leinwin10 小时前
微软发布新一代存储优化型虚拟机:Azure Laosv4、Lasv4 和 Lsv4 系列
microsoft·azure
weixin_3077791311 小时前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习