Sort a linked list using insertion sort.

 /**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* insertionSortList(struct ListNode* head)
{
struct ListNode *p;
p=head;
int count=;
while(p!=NULL)
{
count++;
p=p->next;
} int *array;
array=(int *)malloc(count*sizeof(int)); p=head;
int i=,j,k;
while(p!=NULL)
{
array[i]=p->val;
p=p->next;
i++;
} for(i=;i<count;i++)
{
for(j=i-;j>=;j--)
{
if(array[j]<array[i])
break;
} if(j!=i-)
{
int tmp=array[i];
for(k=i-;k>j;k--)
{
array[k+]=array[k];
}
array[k+]=tmp;
}
} i=;
struct ListNode *q;
q=head;
while(q!=NULL)
{
q->val=array[i];
q=q->next;
i++;
} return head;
}

最新文章

  1. Linux测试环境部署tomcat(二)
  2. GDB常用命令
  3. VC++ 动态生成 成组的 RadioButton 按钮组
  4. [Intellij IDEA]File size exceeds configured limit(2560000). Code insight features are not available
  5. 从今天开始每天刷一题,并写在这里 分类: ACM 2015-06-16 23:52 14人阅读 评论(0) 收藏
  6. python写的多线程下载工具
  7. delete 指针
  8. 为什么用户主目录下.bash_profile没有自动执行
  9. S3C6410 纯粹的裸机启动,自己写的SD BOOT启动
  10. Codeforces 396B On Sum of Fractions 数论
  11. Android四种Activity的加载模式(转)
  12. jquery对象介绍及一些jquery小特效
  13. [bzoj1566][NOI2009]管道取珠
  14. 在mmdetection中跑通MaskRCNN
  15. NetworkStream介绍说明
  16. Github+HEXO FATAL bad indentation of a mapping entry at line 84
  17. WKWebView实现网页静态资源优先从本地加载
  18. 如何将Revit明细表导出为Excel文档
  19. vue开发 - 将方法绑定到window对象,给app端调用
  20. FTP中各文件目录的说明

热门文章

  1. PhpForm表单相关的超全局变量操作
  2. HDU 1251 字典树(前缀树)
  3. Android实现Live Photos 加源代码
  4. ios 导航栏和旋屏
  5. [最新版]MJRefresh解析与详细使用指导
  6. Udp实现简单的聊天程序
  7. Bom和Dom编程以及js中prototype的详解
  8. 【Oracle】逻辑结构(TableSpace→Segment→Extent→Block)
  9. Duanxx的STM32学习:STM32命名规则
  10. android自己定义ViewPager之——3D效果应用