Skip to content

dongtingshuo/data-structures-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Structures & Algorithms / 数据结构与算法练习

English | 中文

Overview / 项目简介

EN: This repository contains C implementations of five classic algorithm problems, with test data and run instructions. It is suitable for algorithm practice, coursework review, and portfolio display.

中文:本仓库收录 5 个经典算法题的 C 语言实现,包含测试数据与运行说明,适合算法练习、课程复习与项目展示。

Directory Structure / 目录结构

八皇后/
  八皇后问题.c
背包/
  背包问题.c
  背包测试数据.txt
哈夫曼/
  哈夫曼编码.c
  README.md
  tobetrans.dat
  简单测试.txt
  测试数据.txt
滑雪场/
  滑雪场问题.c
  小测试数据.txt
  滑雪场测试数据.txt
木棒加工/
  木棒加工问题.c
  木棒加工测试数据.txt

Unified Build Command / 统一编译方式

Run the following command in the corresponding problem directory. / 在对应目录下执行:

gcc -std=c11 -O2 -Wall -Wextra -o 程序名 源文件名.c

Example / 示例:

cd 八皇后
gcc -std=c11 -O2 -Wall -Wextra -o 八皇后问题 八皇后问题.c
./八皇后问题

Problems / 题目说明

Eight Queens (Backtracking) / 八皇后(回溯法)

  • File / 文件:八皇后/八皇后问题.c
  • Function / 功能:Outputs all valid solutions and the total count. / 输出 8 皇后所有可行解与总数量。
  • Input / 输入:None / 无。
  • Output / 输出:Coordinate list for each solution and the total solution count. / 每个解的坐标列表与总解数。

Knapsack (Backtracking Enumeration) / 背包(回溯枚举)

  • File / 文件:背包/背包问题.c
  • Function / 功能:Enumerates all feasible combinations under a given capacity. / 在给定容量下枚举所有可行组合。
  • Input / 输入:Capacity, item count, and item volume list. / 背包容量、物品数量、物品体积列表。
  • Output / 输出:All feasible solutions and the total solution count. / 所有可行解与解的总数。
  • Test data / 测试数据:背包/背包测试数据.txt

Huffman Coding (Tree + Encode/Decode) / 哈夫曼编码(树构建 + 编码/解码)

  • File / 文件:哈夫曼/哈夫曼编码.c
  • Function / 功能:Builds a Huffman tree and performs encoding/decoding. / 构建哈夫曼树并进行编码/解码。
  • Input / 输入:Characters and weights during initialization; tobetrans.dat during encoding. / 初始化时输入字符与权重;编码时读取 tobetrans.dat
  • Output / 输出:Encoded codefile and decoded textfile. / 编码文件 codefile 与解码结果 textfile
  • Notes / 说明:See 哈夫曼/README.md for detailed steps. / 哈夫曼/README.md 内含更详细的操作步骤。

Skiing Path (DFS + Memoization) / 滑雪场(DFS + 记忆化搜索)

  • File / 文件:滑雪场/滑雪场问题.c
  • Function / 功能:Finds the longest ski path length and route. / 求最长滑行路径长度与具体路线。
  • Input / 输入:Matrix dimensions and height matrix. / 矩阵行列数与高度矩阵。
  • Output / 输出:Longest path length, start point, and path. / 最长路径长度、起点与路径。
  • Test data / 测试数据:滑雪场/滑雪场测试数据.txt

Stick Processing (Greedy Grouping) / 木棒加工(贪心分组)

  • File / 文件:木棒加工/木棒加工问题.c
  • Function / 功能:Minimizes preparation time and outputs the processing order. / 最小化准备时间并给出加工顺序。
  • Input / 输入:Stick count plus each stick's length and weight. / 木棒数量与每根木棒的长度、重量。
  • Output / 输出:Minimum preparation time and processing order. / 最少准备时间与加工顺序。
  • Test data / 测试数据:木棒加工/木棒加工测试数据.txt

Run Notes / 运行说明

  • Programs use standard input by default. / 默认使用标准输入(终端交互)。
  • Huffman coding generates temporary files: huffman, codefile, codeprint, textfile, and treeprint; they are ignored by .gitignore. / 哈夫曼编码会生成临时文件:huffmancodefilecodeprinttextfiletreeprint,这些文件已加入 .gitignore

License / 许可协议

MIT License. See LICENSE. / MIT License,详见 LICENSE

About

C 语言数据结构与算法练习集合 / C implementations of classic data structures and algorithm exercises.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages