码迷,mamicode.com
首页 >  
搜索关键字:listnode    ( 1413个结果
题目:输入一个链表的头结点,反转该链表,并返回反转后链表的头结点。
题目:输入一个链表的头结点,反转该链表,并返回反转后链表的头结点。链表结点定义如下: struct ListNode {     int       m_nKey;     ListNode* m_pNext; }; c语言实现 /* File : rlink.c Author : Date : 2015/4/4 platform : windows7 x86_64 ve...
分类:其他好文   时间:2015-04-04 22:40:01    阅读次数:260
Leetcode: Insertion Sort List
题目:Sort a linked list using insertion sort. 即使用插入排序对链表进行排序。思路分析: 插入排序思想见《排序(一):直接插入排序 》C++参考代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *...
分类:其他好文   时间:2015-04-04 22:39:14    阅读次数:154
LeetCode - Merge Two Sorted Lists
依然是链表的简单操作,把两个链表按大小顺序和成一个链表,但是还是要注意细节。下面是效率不高但是简单易懂的一种解法。需要注意两个链表都为空的情况。/** * Definition for singly-linked list. * public class ListNode { * int ...
分类:其他好文   时间:2015-04-03 01:30:40    阅读次数:111
LeetCode - Remove Nth Node From End of List
删除链表中倒数第n个节点,需要考虑的细节:链表为空时,链表只有一个节点时,n=1时。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ...
分类:其他好文   时间:2015-04-02 20:50:41    阅读次数:108
leetcode_num179_Insertion Sort list
Sort a linked list using insertion sort. 举例子真是写对代码的好方法! /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NU...
分类:其他好文   时间:2015-04-01 23:56:33    阅读次数:306
【LeetCode OJ】Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. struct ListNode { int val; ListNode *next; ListNo...
分类:其他好文   时间:2015-04-01 09:31:07    阅读次数:131
Merge Two Sorted Lists
合并有序两个链表 class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { ListNode* res = new ListNode(0); if (l1 == NULL) { return l2; }...
分类:其他好文   时间:2015-03-31 21:50:59    阅读次数:134
数据结构学习1---链表
带头节点单链表 数据结构定义 ListNode.h #ifndef LISTNODE_H #define LISTNODE_H template class ListNode { private: T data; ListNode *next; public: ListNode(); ListNode(T value); int Getdata(); ListNode* Ge...
分类:其他好文   时间:2015-03-31 14:51:11    阅读次数:201
链表的排序 时间复杂度O(nlogn)
思路:用归并排序。对一个链表采用递归进行二等分,直到每个部分有序,然后对其进行合并。其实就是两步,先分解,然后合并有序链表。代码://对链表采用递归排序class Solution {public: ListNode* sortList(ListNode* head){ if(h...
分类:编程语言   时间:2015-03-31 00:23:10    阅读次数:224
leetcode_num148_Sort list
链表的归并排序 特别注意取中值函数的书写 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { ...
分类:其他好文   时间:2015-03-30 21:15:46    阅读次数:172
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!