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"

待完善......

相关推荐
05Kevin11 小时前
lk每日冒险题--数据结构6.27
算法
To_OC21 小时前
从一次栈溢出报错说起,我把递归彻底扒明白了
javascript·算法·程序员
千纸鹤安安1 天前
千问Qwen-AgentWorld来了:一个语言模型搞定七大Agent场景,GPT-5.4都输了
算法
七牛开发者1 天前
MCP 到底是什么?为什么 Agent 都想接上它
算法·aigc·agent
北域码匠1 天前
冒泡排序太慢?鸡尾酒排序双向优化,原生 C# 零第三方库完整代码
数据结构·排序算法·泛型·c# 算法·鸡尾酒排序·原生 c# 开发·冒泡排序优化·嵌入式算法
kisshyshy1 天前
从递归到迭代,一文吃透二叉树的核心知识与 JavaScript 实现
javascript·算法·代码规范
To_OC2 天前
LC 49 字母异位词分组:想到哈希表很简单,选对 key 才是精髓
javascript·算法·leetcode
用户938515635072 天前
从 O(n²) 到 O(nlogn):一文读懂快速排序的“快”与“妙”
javascript·算法