反转一个单链表。
示例:
输入: 1->2->3->4->5->null 输出: 5->4->3->2->1->null
进阶:
你可以迭代或递归地反转链表。你能否用两种方法解决这道题?
/** * definition for singly-linked list. * struct listnode { * int val; * struct listnode *next; * }; */ struct listnode* reverselist(struct listnode* head) { if (null == head || null == head->next) { return head; } struct listnode* a=head; struct listnode* b=head->next; struct listnode* c; head->next = null; while (b) { c = b->next; b->next = a; a = b; b = c; } head = a; return head; }
如对本文有疑问, 点击进行留言回复!!
clion+vs编译器+Qt5中使用QPrinter和QprintDialog类
基于open62541在QT编写OPCUA特定的客户端程序(含有源码) + VS2015 C语言搭建OPCUA客户端环境
网友评论