mirror of
https://github.com/xusun0623/exam_code_for_408.git
synced 2026-02-02 18:09:04 +08:00
update:提交2023年408数据结构算法题代码
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
cmake-build-debug
|
||||
CMakeLists.txt
|
||||
.idea
|
||||
*.exe
|
||||
*.exe
|
||||
.out
|
||||
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@@ -1,8 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
14
.vscode/c_cpp_properties.json
vendored
14
.vscode/c_cpp_properties.json
vendored
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"cStandard": "c18",
|
||||
"compilerPath": "C:\\Program Files\\mingw64\\mingw64\\bin\\gcc.exe",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"intelliSenseMode": "windows-gcc-x64",
|
||||
"name": "Win32"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
41
.vscode/launch.json
vendored
41
.vscode/launch.json
vendored
@@ -1,26 +1,21 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"MIMode": "gdb",
|
||||
"args": [],
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"miDebuggerPath": "C:\\Program Files\\mingw64\\mingw64\\bin\\gdb.exe",
|
||||
"name": "gcc single file debug",
|
||||
"preLaunchTask": "gcc single file build",
|
||||
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
|
||||
"request": "launch",
|
||||
"setupCommands": [
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"ignoreFailures": true,
|
||||
"text": "-enable-pretty-printing"
|
||||
"name": "(lldb) 启动",
|
||||
"preLaunchTask": "C/C++: clang++ 生成活动文件",//调试前执行的任务,就是之前配置的tasks.json中的label字段
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/.out/${fileBasenameNoExtension}.out",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "lldb"
|
||||
}
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"type": "cppdbg"
|
||||
}
|
||||
],
|
||||
"version": "0.2.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
66
.vscode/tasks.json
vendored
66
.vscode/tasks.json
vendored
@@ -1,41 +1,29 @@
|
||||
{
|
||||
"options": {
|
||||
"env": {
|
||||
"Path": "C:\\Program Files\\mingw64\\mingw64\\bin;${env:Path}"
|
||||
},
|
||||
"shell": {
|
||||
"args": [
|
||||
"/C"
|
||||
],
|
||||
"executable": "C:\\Windows\\System32\\cmd.exe"
|
||||
}
|
||||
},
|
||||
"tasks": [
|
||||
{
|
||||
"args": [
|
||||
"-std=c18",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}\\${fileBasenameNoExtension}.exe"
|
||||
],
|
||||
"command": "C:\\Program Files\\mingw64\\mingw64\\bin\\gcc.exe",
|
||||
"group": {
|
||||
"isDefault": true,
|
||||
"kind": "build"
|
||||
},
|
||||
"label": "gcc single file build",
|
||||
"presentation": {
|
||||
"clear": true,
|
||||
"echo": false,
|
||||
"focus": false,
|
||||
"panel": "shared",
|
||||
"reveal": "silent",
|
||||
"showReuseMessage": false
|
||||
},
|
||||
"problemMatcher": "$gcc",
|
||||
"type": "process"
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: clang++ 生成活动文件",
|
||||
"command": "/usr/bin/clang++",
|
||||
"args": [
|
||||
"-fcolor-diagnostics",
|
||||
"-fansi-escape-codes",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${workspaceFolder}/.out/${fileBasenameNoExtension}.out"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "调试器生成的任务。"
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
51
2023_get_kVertice.cpp
Normal file
51
2023_get_kVertice.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define MAXV 4
|
||||
|
||||
typedef struct { // 图的定义
|
||||
int numVertices, numEdges; // 图中实际的顶点数和边数
|
||||
char VerticesList[MAXV]; // 顶点表,MAXV为已定义常量
|
||||
int Edge[MAXV][MAXV]; // 邻接矩阵
|
||||
} MGraph;
|
||||
|
||||
int printVertices(MGraph* G) {
|
||||
int count = 0, indegree = 0, outdegree = 0;
|
||||
// 遍历无向图统计所有点的出度和入度
|
||||
for (int i = 0; i < G->numVertices; i++) {
|
||||
indegree = 0; // i的入度
|
||||
outdegree = 0; // i的出度
|
||||
for (int j = 0; j < G->numVertices; j++) {
|
||||
outdegree += G->Edge[i][j];
|
||||
indegree += G->Edge[j][i];
|
||||
}
|
||||
if (outdegree > indegree) {
|
||||
printf("K顶点的个数为:%d\n", i);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MGraph* m = new MGraph();
|
||||
m->numVertices = 4;
|
||||
m->numEdges = 5;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
m->VerticesList[i] = 'a' + i;
|
||||
}
|
||||
/**
|
||||
* m->Edge
|
||||
* [0,1,0,1]
|
||||
* [0,0,1,1]
|
||||
* [0,0,0,1]
|
||||
* [0,0,0,0]
|
||||
*/
|
||||
m->Edge[0][1] = 1;
|
||||
m->Edge[0][3] = 1;
|
||||
m->Edge[1][2] = 1;
|
||||
m->Edge[1][3] = 1;
|
||||
m->Edge[2][3] = 1;
|
||||
printVertices(m);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user