0
点赞
收藏
分享

微信扫一扫

Three 三维矩阵(Matrix3)、四维矩阵(Matrix4)

沐之轻语 2024-07-27 阅读 33

-------------------------------------------------------------------

给一个无单向不循环链表的首结点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头文件中声明,所以在使用前需要包含头文件

        1、排序

                1)sort()(基于快排实现)
                2)stable_sort(基于归并实现)
                3)partial_sort(基于交换元素存储位置实现)

        2、查找         

                1)find(基于==运算符)
                 2)find_if(基于==运算符)
举报

相关推荐

0 条评论