leetcode做题总结,题目Insertion Sort List 2013/11/12
来源:互联网 发布:硕鼠mac 下载打不开 编辑:程序博客网 时间:2024/06/05 18:33
非容器链表的插入排序,和数组不一样的是插入时指针要从前往后扫,而且注意的是除非没有插入操作,否则指针是不用前进的,因为把指针的next插入到了前面,所以又指向新的节点了。
public ListNode insertionSortList(ListNode head) { if(head==null)return null; ListNode start = new ListNode(0); start.next=head; ListNode p=head; ListNode q; ListNode tmp; int cha=0; while(p.next!=null){ tmp=p.next; q=start; cha=0; while(q!=p){ if(q.next.val>=tmp.val){ p.next=tmp.next; tmp.next=q.next; q.next=tmp; //p=p.next; cha=1; break; } q=q.next; } if(cha==0){ p=p.next; } } return start.next; }
0 0
- leetcode做题总结,题目Insertion Sort List 2013/11/12
- leetcode做题总结,题目Sort List 2013/11/16
- leetcode题目解答---Insertion Sort List
- LeetCode题目5:Insertion Sort List
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Leetcode: Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- [LeetCode] Insertion Sort List
- Insertion Sort List (LeetCode)
- [LeetCode] Insertion Sort List
- [LeetCode]Insertion Sort List
- leetcode Insertion Sort List
- 线段树题集
- 揭秘socket编程的面纱
- Java多线程总结
- MODBUS TCP和MODBUS RTU的差别
- hdu 4893 Wow! Such Sequence! 水线段树。
- leetcode做题总结,题目Insertion Sort List 2013/11/12
- OC 第五讲 字符串
- Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)
- iOS 创建静态库文件时去掉其中的Symbols
- poj1548
- ACM 线段树模板 hdu 4893 Wow! Such Sequence!
- hdu 4893 Wow! Such Sequence!
- ——java中的注解
- HDU 1455——Sticks(神棍)