链表相关面试题
来源:互联网 发布:abp源码 编辑:程序博客网 时间:2024/05/22 03:20
使用插入排序对链表进行排序(Sort a linked list using insertion sort.):
public ListNode insertionSortList(ListNode head) { if (head == null) { return head; } ListNode toInsert = head; ListNode newHead = null; while (toInsert != null) { ListNode cur = newHead; ListNode next = toInsert.next; // 判断头部 if (cur == null||toInsert.val <= newHead.val) { toInsert.next = cur; newHead = toInsert; } else { while (cur.next != null) { if (cur.val <= toInsert.val && toInsert.val <= cur.next.val) { toInsert.next = cur.next; cur.next = toInsert; break; } cur =cur.next; } //如果待插入的数是最大的,就把它放在后面 if (cur.next == null) { cur.next = toInsert; toInsert.next = null; } } toInsert = next; } return newHead; }
阅读全文
0 0
- 链表相关面试题
- 链表相关面试题
- 链表相关面试题
- 链表相关面试题
- 链表相关面试题
- 链表相关面试题(zz)
- 常见的链表相关面试题
- 链表相关的面试题总结
- [各种面试题] 链表相关
- 链表的相关面试题
- 链表相关面试题(一)
- 链表相关面试题(二)
- 链表的相关面试题
- 链表相关面试题总结大全
- 【链表复习】链表相关面试题
- 顺序表和链表的相关热点面试题
- 【每日面试题】链表相关问题1
- 【每日面试题】链表相关问题2
- python实现对其它主机的操作
- Spring Boot + Spring Data + Elasticsearch example
- Eclipse Java注释模板设置详解
- MVVM模式
- 向量内积–笔记2017年10月3日
- 链表相关面试题
- 如何将PHP作为Shell脚本语言使用
- 关于DL中的过拟合中的dropout
- abstract class和interface
- 卡特兰数
- leetcode.array--4. Median of Two Sorted Arrays
- stdlib.h和stdio.h的区别
- CSS Mastery摘要(2)--Visual Formatting Model Overview
- Android移动开发-使用OpenGL来绘制3D纹理图的实现