Singly linked list inversion, without creating new nodes, only by recombining existing nodes_Complete singly linked list inversion without additional arrays or nodes_Whirlwind Charge Tornado_’s blog

class=”markdown_views prism-atom-one-dark”> Algorithm idea: To reverse the singly linked list, you should first think of using the head interpolation method, but it is required not to create a new node, you can use the elements in L as the insertion object, and set L->next to empty. Then the elements are inserted into L one by one using the head interpolation method. void reverse(LNode* L) { LNode* p = L->next; LNode* q; L->next = NULL; while (p) { q = p->next;//q is used to record the successor node of p p->next = L->next;//The node pointed to by p is inserted into a new linked list L->next = p; p = q; } }

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索