由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - linklist exercise
相关主题
remove a node (and its memory) from a doubly linked list我恨iPhone@Facebook电面
Populating Next Right Pointers in Each Node IIremove a node in O(1) from link list
reverse random pointers of a single linked listlevel order nodes
关于python interview【我自己写的LinkedList为什么总有错?】
说个面经,回答我前面的那个帖子,和G有关,主要是教训啦,问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5
"简单的"linklist的问题amazon onsite 面经
reverse链表问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,
请教linked list, 删除最后一个节点面试面试官错了怎么办?
相关话题的讨论汇总
话题: null话题: nodes话题: tnext话题: unext话题: linklist
进入JobHunting版参与讨论
1 (共1页)
c***2
发帖数: 838
1
Write a function for a linked list that exchanges the positions
of the nodes after the nodes referenced by two given pointers t and u.
(assume t and u are either in the list or NULL).
Example:
1 2 4 3 6 8 5 7 9 10
Exchange nodes after 2 and 3:
1 2 6 3 4 8 5 7 9 10
1) Don't do it by exchanging data.
2) Consider all possible cases.
t**d
发帖数: 352
2
what can be all all possible cases? all u,t, u,next() and t.next() have to
be not null, otherwise this function has no meaning.
so
if (t == null || u == null ) throw new NullPointerException();
if (t == u) return;
linkedList tnext = t.next();
linkedList unext = u.next();
if (tnext == null || unext == null ) throw new NullPointerException();
t._next = unext;
u._next = tnext;
linkedList temp = tnext.next();
tnext._next = unext.next();
unext._next = temp;
c***2
发帖数: 838
3
you are right and good. :-)
There is another valid case: one of them is NULL, the other is not.
In which case, move the non-null one to end of list.
1 (共1页)
进入JobHunting版参与讨论
相关主题
面试面试官错了怎么办?说个面经,回答我前面的那个帖子,和G有关,主要是教训啦,
判断linkedlist是否palindrome最优解法是什么?"简单的"linklist的问题
求个java版本的binary tree serialization和deserializationreverse链表
菜鸟 贴一个 leetcode LRU Cache -- java代码,并求解疑惑。请教linked list, 删除最后一个节点
remove a node (and its memory) from a doubly linked list我恨iPhone@Facebook电面
Populating Next Right Pointers in Each Node IIremove a node in O(1) from link list
reverse random pointers of a single linked listlevel order nodes
关于python interview【我自己写的LinkedList为什么总有错?】
相关话题的讨论汇总
话题: null话题: nodes话题: tnext话题: unext话题: linklist