开发者

about linked list

Hi I have a question that :

for example I have a linked list that has 4 elements. [1,4,2,7] and their in开发者_如何转开发dex will be 0,1,2,3. when I remove the third element which is "2" and it index is 2 ,the index of fourth element will be 2 ,I mean that the index of "7" will be 2? my problem is because of the code bellow.

with doubly linked list we can write such a this code:

(p1--> next) = p3;(p3-->prev)=p1;delete p2;p1 = (p1.prev);

how can i write it for linked list? thanks


in java you just have the following for a linked list. You don't need to/can't delete a node.

p1.next = p3;

Note: you would only do this if it is homework. In the real world, you should use the builtin, well understood and tested classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜