码迷,mamicode.com
首页 >  
搜索关键字:listnode    ( 1413个结果
算法:链表
通过链表的一些题目,了解链表的基本操作实现,掌握递归算法的基本思路,掌握扎实的编程习惯。一、单链表基本操作1.1、单链表节点定义struct ListNode{ int value; ListNode *pNext;};1.2、在尾部插入节点void AddToTail(ListNode...
分类:其他好文   时间:2014-07-16 20:33:24    阅读次数:150
注意链表的尾部
今天做了Leetcode上面一道题Remove Duplicates from Sorted List II,要去去除链表中重复的节点,代码如下 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * ...
分类:其他好文   时间:2014-07-13 21:23:10    阅读次数:160
Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? /** * Definition for singly-linked list. * class ListNode { * int val; * ...
分类:其他好文   时间:2014-07-13 16:32:04    阅读次数:152
Insertion Sort List
不知道为什么{3,4,1}就是通不过。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), n...
分类:其他好文   时间:2014-07-13 12:25:11    阅读次数:236
【LeetCode】Insertion Sort List
题目 Sort a linked list using insertion sort. 解答 链表无法像数组那样从后往前依次比较插入,只能从前往后;在链表首部添加一个哨兵可以稍微简化下代码,代码如下: /** * Definition for singly-linked list. * public class ListNode { * int val; * ...
分类:其他好文   时间:2014-07-11 08:06:49    阅读次数:362
【剑指offer】Q17:合并两个排序的链表
def Merge(head1, head2): if head1 == None: return head2 if head2 == None: return head1 psuhead = ListNode(-1) tail = psuhead while head1 and head2: if head1.val < head2.val: cur = head1 ...
分类:其他好文   时间:2014-07-08 18:46:04    阅读次数:227
【剑指offer】Q16:翻转链表
def reverse(head): if head == None or head.next == None: return head psuhead = ListNode(-1) while head: nexthead = head.next head.next = psuhead.next psuhead.next = head head = nexthead ...
分类:其他好文   时间:2014-07-08 15:27:58    阅读次数:183
[leetcode] Insertion Sort List(python)
简单的插入排序,总是超时,暂且放在这记录一下。 class Solution: # @param head, a ListNode # @return a ListNode def insertionSortList(self, head): if head == None or head.next == None: return head psuhead...
分类:编程语言   时间:2014-07-06 11:52:20    阅读次数:230
单链表反转python实现
单链表的反转可以使用循环,也可以使用递归的方式 1.循环反转单链表 循环的方法中,使用pre指向前一个结点,cur指向当前结点,每次把cur->next指向pre即可。      代码: class ListNode: def __init__(self,x): self.val=x; self.next=None; def nonrecurse(he...
分类:编程语言   时间:2014-07-06 00:24:52    阅读次数:331
链表节点类化
用c++类将单向链表类化,保存后可以方便的进行数的排序,插入操作; 调试成功的!#include using namespace std;class ListNode//创造节点成分{public: ListNode(int datavalue)//构造函数一 { value=datavalue.....
分类:其他好文   时间:2014-07-05 21:48:08    阅读次数:175
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!