-------------------------------------------------------------------
给一个无单向不循环链表的首结点l,编写程序反转链表,并返回反转后的链表首结点
struct llist_node {
int val;
struct llist_node *next;
};
struct llist_node *func(struct llist_node *l)
{
struct llist_node *cur = l;
struct llist_node *prev = NULL; // 指向链表当前节点的上一个节点
struct llist_node *next = NULL; // 指向链表当前节点的下一个节点
while (cur) {
next = cur->next;
cur->next = prev;
prev = cur;
cur = next;
}
return cur;
}
-------------------------------------------------------------------
二、STL模板库----算法(algorithm)
我们所有的算法都是在algorithm头文件中声明,所以在使用前需要包含头文件