连接两个链表。

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

}

相关推荐
.小墨迹6 小时前
apollo学习之借道超车的速度规划
linux·c++·学习·算法·ubuntu
山岚的运维笔记6 小时前
SQL Server笔记 -- 第20章:TRY/CATCH
java·数据库·笔记·sql·microsoft·sqlserver
Lsir10110_6 小时前
【Linux】中断 —— 操作系统的运行基石
linux·运维·嵌入式硬件
Sheffield7 小时前
command和shell模块到底区别在哪?
linux·云计算·ansible
历程里程碑7 小时前
Linux20 : IO
linux·c语言·开发语言·数据结构·c++·算法
郝学胜-神的一滴7 小时前
深入浅出:使用Linux系统函数构建高性能TCP服务器
linux·服务器·开发语言·网络·c++·tcp/ip·程序人生
承渊政道7 小时前
Linux系统学习【Linux系统的进度条实现、版本控制器git和调试器gdb介绍】
linux·开发语言·笔记·git·学习·gitee
技术路上的探险家7 小时前
Ubuntu下Docker与NVIDIA Container Toolkit完整安装教程(含国内源适配)
linux·ubuntu·docker
代码AC不AC7 小时前
【Linux】深入理解缓冲区
linux·缓冲区·标准错误
Doro再努力7 小时前
【Linux操作系统12】Git版本控制与GDB调试:从入门到实践
linux·运维·服务器·git·vim