Redian新闻
>
出个全新的hhkb type-s键盘
avatar
出个全新的hhkb type-s键盘# Hardware - 计算机硬件
c*2
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.
avatar
t*u
2
avatar
t*d
4
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;
avatar
d*y
5
一周吧,我的好像是今天到,ups还没送过来,还不确定是不是的。
avatar
c*2
6
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.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。