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"

待完善......

相关推荐
im_AMBER6 分钟前
Leetcode 115 分割链表 | 随机链表的复制
数据结构·学习·算法·leetcode
Liue612312317 分钟前
【YOLO11】基于C2CGA算法的金属零件涂胶缺陷检测与分类
人工智能·算法·分类
数智工坊8 分钟前
【数据结构-树与二叉树】4.7 哈夫曼树
数据结构
!!!!81312 分钟前
蓝桥备赛Day1
数据结构·算法
Mr_Xuhhh12 分钟前
介绍一下ref
开发语言·c++·算法
七点半77012 分钟前
linux应用编程部分
数据结构
夏鹏今天学习了吗16 分钟前
【LeetCode热题100(99/100)】柱状图中最大的矩形
算法·leetcode·职场和发展
静听山水16 分钟前
Redis核心数据结构-Hash
数据结构·redis·哈希算法
啊阿狸不会拉杆22 分钟前
《机器学习导论》第 9 章-决策树
人工智能·python·算法·决策树·机器学习·数据挖掘·剪枝
Mr_Xuhhh23 分钟前
C++11实现线程池
开发语言·c++·算法