Change index in a linked list in c

爱⌒轻易说出口 提交于 2020-07-10 07:52:06

问题


Can anyone help me with finding an algorithm to change a position of a node in a linked list according to the input?

Example:

I have the linked list: 1->2->3->4->END and the user chose the second node and the index 4.

The algorithm will give us the result: 1->3->4->2->END.

Thanks for your help!


回答1:


It is really easy to move nodes in a linked list because they are done for that...

To change a node's position, just change it's next pointer to the next node address, and the previous node's next pointer to the node you want to move and that's done.



来源:https://stackoverflow.com/questions/50888911/change-index-in-a-linked-list-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!