博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeeCode-Insertion Sort List
阅读量:6935 次
发布时间:2019-06-27

本文共 1041 字,大约阅读时间需要 3 分钟。

Sort a linked list using insertion sort.

 

1 /** 2  * Definition for singly-linked list. 3  * struct ListNode { 4  *     int val; 5  *     struct ListNode *next; 6  * }; 7  */ 8 struct ListNode* insertionSortList(struct ListNode* head)  9 {10     struct ListNode *p;11     p=head;12     int count=0;13     while(p!=NULL)14     {15         count++;16         p=p->next;17     }18 19     int *array;20     array=(int *)malloc(count*sizeof(int));21 22     p=head;23     int i=0,j,k;24     while(p!=NULL)25     {26         array[i]=p->val;27         p=p->next;28         i++;29     }30 31     for(i=1;i
=0;j--)34 {35 if(array[j]
j;k--)43 {44 array[k+1]=array[k];45 }46 array[k+1]=tmp;47 }48 } 49 50 i=0;51 struct ListNode *q;52 q=head;53 while(q!=NULL)54 {55 q->val=array[i];56 q=q->next;57 i++;58 }59 60 61 return head;62 }

 

转载于:https://www.cnblogs.com/vpoet/p/4660540.html

你可能感兴趣的文章
OKR
查看>>
cmake 常用变量和常用环境变量查表手册
查看>>
H极大值—lhMorpHMax
查看>>
asp.net创建文件夹出错的解决方案[转]
查看>>
[php] stop the NetBeans to scan the files automaticly
查看>>
都老了
查看>>
RFM模型分析与客户细分
查看>>
user-select介绍
查看>>
src源代码生成html格式文档
查看>>
一道面试题:用多种方法实现两个数的交换
查看>>
网络之XML解析-原生
查看>>
Linux下安全扫描工具Nmap用法详解
查看>>
linux系统编程:线程原语
查看>>
MIDI Architecture
查看>>
设计中最常用的CSS选择器
查看>>
关于Cocos2d-x中增加暂停按钮的步骤
查看>>
Nginx的继续深入(日志轮询切割,重写,负载均衡等)
查看>>
hdoj:2083
查看>>
log4j(七)——log4j.xml简单配置样例说明
查看>>
用express-generator创建express项目骨架
查看>>