408数据结构常考算法基础训练


该训练营为蓝蓝考研蓝颜知己 )的算法训练营内容,题目来源有经典算法题、408统考算法题等等。分为7weeks共计39days 练习,每日一道算法题训练,涵盖基本顺序表、链表和二叉树相关的基础算法,以及部分408真题 中数据结构部分的算法题,并未包含图相关的算法,还需要进一步对图算法自行学习。
github项目地址--AlgorithmTrainingCamp

如果时间充裕,可以前期进行PC端练习,后期再尝试完全在纸上进行手写练习;如果时间紧张则不建议PC端练习,直接手写。

个人最初是使用的Clion进行coding练习的,所以这些题目是可以成功测试运行的。所涉及的相关结构体及函数定义如下所示:

  • 线性表List
    • 顺序表SqList
      • 头文件SqList.h
cpp 复制代码
// SqList.h
// Created by Giperx on 2023/7/24.
//
#ifndef ALGCAMP_SEQLIST_H
#define ALGCAMP_SEQLIST_H
// 顺序表
typedef struct SqList{
 int data[100];
 int length;
}SqList;
// 初始化顺序表
void initSqList(SqList &list);
// 打印输出顺序表
void printSqList(SqList &list);
#endif //ALGCAMP_SEQLIST_H
  • 线性表List
    • 顺序表SqList
      • SqList.cpp
cpp 复制代码
//SqList.cpp
// Created by Giperx on 2023/7/27.
//
#include <iostream>
#include "SqList.h"
using namespace std;
void initSqList(SqList &list){
    cout << "enter length of SqList:";
    cin >> list.length;
    cout << "enter values of SqList:";
    for(int i = 0; i < list.length; i ++) cin >> list.data[i];
}
void printSqList(SqList &list){
    cout << "length: " << list.length << endl;
    for(int i = 0; i < list.length; i ++) cout << list.data[i] << ' ';
    cout << endl;
}
  • 线性表List
    • 链表LinkList
      • 头文件LinkList.h
cpp 复制代码
//LinkList.h
// Created by Giperx on 2023/8/15.
//
#ifndef ALGCAMP_LINKLIST_H
#define ALGCAMP_LINKLIST_H
typedef struct LNode{
    int data;
    struct LNode *next;
    LNode(int val){
        data = val;
        next = nullptr;
    }
}LNode, *LinkList;
// 初始化链表,带头结点
bool initLinkList(LinkList& L);
// 计算链表长度(不包括头结点)
int lengthofLinkList(LinkList& L);
// 输出链表信息
void printLinkList(LinkList& L);
#endif //ALGCAMP_LINKLIST_H
  • 线性表List
  • 链表LinkList
    • LinkList.cpp
cpp 复制代码
//LinkList.cpp
// Created by Giperx on 2023/8/15.
//
#include "LinkList.h"
#include "malloc.h"
#include "iostream"
using namespace std;

// 初始化链表,带头结点
bool initLinkList(LinkList& L){
    L = (LNode*)malloc(sizeof (LNode));
    if (!L) return false;
    L->next = nullptr;
    return true;
}
// 计算链表长度(不包括头结点)
int lengthofLinkList(LinkList& L){
    int length = 0;
    if (!L){
        cout << "nullptr!" << endl;
    } else if (!L->next) {
        cout << "have not node!" << endl;
    } else {
        LNode *p = L->next;
        while (p){
            length++, p = p->next;
        }
    }
    return length;
}
// 输出链表信息
void printLinkList(LinkList& L){
    if (!L) cout << "nullptr!" << endl;
    else if (!L->next) cout << "have not node!" << endl;
    else{
        cout << "length of LinkList:" << lengthofLinkList(L) << endl;
        LNode *p = L->next;
        while (p){
            cout << p->data << ' ';
            p = p->next;
        }
        cout << endl;
    }
}
  • 二叉树
    • BiTree.h
cpp 复制代码
//BiTree.h
// Created by Giperx on 2023/8/24.
//
#ifndef ALGCAMP_BITREE_H
#define ALGCAMP_BITREE_H
// 二叉树
typedef struct BiNode{
    char data;
    struct BiNode* left, *right;
}BiNode, *BiTree;
#endif //ALGCAMP_BITREE_H
  • 二叉树
    • BiTree.cpp
cpp 复制代码
//BiTree.cpp
// Created by Giperx on 2023/8/24.
//
#include "BiTree.h"

待完善......

相关推荐
白杆杆红伞伞9 分钟前
01_svm_二分类
算法·支持向量机·分类
isyoungboy11 分钟前
使用SVM构建光照鲁棒的颜色分类器:从特征提取到SVM
算法·机器学习·支持向量机
极客数模12 分钟前
2025年MathorCup 大数据竞赛明日开赛,注意事项!论文提交规范、模板、承诺书正确使用!2025年第六届MathorCup数学应用挑战赛——大数据竞赛
大数据·python·算法·matlab·图论·比赛推荐
.小小陈.22 分钟前
数据结构3:复杂度
c语言·开发语言·数据结构·笔记·学习·算法·visual studio
立志成为大牛的小牛23 分钟前
数据结构——二十四、图(王道408)
数据结构·学习·程序人生·考研·算法
TT哇29 分钟前
【优先级队列(堆)】2.数据流中的第 K ⼤元素(easy)
算法·1024程序员节
Matlab程序猿小助手1 小时前
【MATLAB源码-第303期】基于matlab的蒲公英优化算法(DO)机器人栅格路径规划,输出做短路径图和适应度曲线.
开发语言·算法·matlab·机器人·kmeans
CoderIsArt1 小时前
CORDIC三角计算技术
人工智能·算法·机器学习
立志成为大牛的小牛1 小时前
数据结构——二十九、图的广度优先遍历(BFS)(王道408)
数据结构·数据库·学习·程序人生·考研·算法·宽度优先
Alex艾力的IT数字空间1 小时前
基于PyTorch和CuPy的GPU并行化遗传算法实现
数据结构·人工智能·pytorch·python·深度学习·算法·机器学习