摘要:
void delete_node(Node *head, Node *node) { Node *next = node->next;if(next==NULL) { /* if the node is the tail of the list */Node *curr_node= head; while(curr_node->next!=node) {curr_node= curr...
阅读全文
posted @ 2010-07-12 23:24
赵情融
阅读(369)
推荐(0)
编辑
摘要:
假设两条链表有公共节点Node, 那么从Node往后的节点必定都是公共节点. 也就是这两个链表成"Y"的形状. 那么两个链表的长度差只会出现在Node之前.Node *find_first_common(Node *head1, Node *head2) { int m = 0; int n = 0; Node *p1 = head1; Node *p2 = head2; int i; while...
阅读全文
posted @ 2010-07-12 23:23
赵情融
阅读(1015)
推荐(0)
编辑
摘要:
1, 最简单的方法, 用一个指针遍历链表, 每遇到一个节点就把他的内存地址(java中可以用object.hashcode())做为key放在一个hashtable中. 这样当hashtable中出现重复key的时候说明此链表上有环. 这个方法的时间复杂度为O(n), 空间同样为O(n).2, 使用反转指针的方法, 每过一个节点就把该节点的指针反向:Boolean reverse(Node *he...
阅读全文
posted @ 2010-07-12 23:22
赵情融
阅读(4781)
推荐(0)
编辑
摘要:
回文,12321。这是一个字符串,字符串的第一个和最后一个相同,第二个和倒数第二个相同,用递归这样来实现回文判断。代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--#include<iostream>usingnamespacestd;b...
阅读全文
posted @ 2010-07-12 23:21
赵情融
阅读(377)
推荐(0)
编辑