用c语言设计一个基于DOS菜单的应用程序。要利用多级菜单实现各种功能。内容如下: 1. 无向图的基本操作及应用 ① 创建无向图的邻接矩阵 ② 创建无向图的邻接表 ③ 无向图的深度优先遍历 ④ 无向图的广度优先遍历 2. 无向网的基本操作及应用 ① 创建无向网的邻接矩阵 ② 创建无向网的邻接表 ③ 求最小生成树 3. 有向图的基本操作及应用 ① 创建有向图的邻接矩阵 ② 创建有向图的邻接表 ③ 拓扑排序 4. 有向网的基本操作及应用 ① 创建有向网的邻接矩阵 ② 创建有向网的邻接表 ③ 关键路径 ④ 单源最短路径 ⑤ 每对顶点之间的最短路径
时间: 2024-01-26 15:04:42 浏览: 81
以下是一个基于DOS菜单的应用程序设计,可供参考:
```c
#include <stdio.h>
#include <conio.h>
void createUndirectedGraphByMatrix() {
printf("You have chosen to create an undirected graph by adjacency matrix.\n");
// TODO: 实现创建无向图邻接矩阵的功能
}
void createUndirectedGraphByList() {
printf("You have chosen to create an undirected graph by adjacency list.\n");
// TODO: 实现创建无向图邻接表的功能
}
void traverseUndirectedGraphByDFS() {
printf("You have chosen to traverse an undirected graph by depth-first search.\n");
// TODO: 实现无向图深度优先遍历的功能
}
void traverseUndirectedGraphByBFS() {
printf("You have chosen to traverse an undirected graph by breadth-first search.\n");
// TODO: 实现无向图广度优先遍历的功能
}
void createUndirectedNetworkByMatrix() {
printf("You have chosen to create an undirected network by adjacency matrix.\n");
// TODO: 实现创建无向网邻接矩阵的功能
}
void createUndirectedNetworkByList() {
printf("You have chosen to create an undirected network by adjacency list.\n");
// TODO: 实现创建无向网邻接表的功能
}
void findMinimumSpanningTree() {
printf("You have chosen to find the minimum spanning tree.\n");
// TODO: 实现求最小生成树的功能
}
void createDirectedGraphByMatrix() {
printf("You have chosen to create a directed graph by adjacency matrix.\n");
// TODO: 实现创建有向图邻接矩阵的功能
}
void createDirectedGraphByList() {
printf("You have chosen to create a directed graph by adjacency list.\n");
// TODO: 实现创建有向图邻接表的功能
}
void topologicalSort() {
printf("You have chosen to do a topological sort.\n");
// TODO: 实现拓扑排序的功能
}
void createDirectedNetworkByMatrix() {
printf("You have chosen to create a directed network by adjacency matrix.\n");
// TODO: 实现创建有向网邻接矩阵的功能
}
void createDirectedNetworkByList() {
printf("You have chosen to create a directed network by adjacency list.\n");
// TODO: 实现创建有向网邻接表的功能
}
void findCriticalPath() {
printf("You have chosen to find the critical path.\n");
// TODO: 实现求关键路径的功能
}
void findShortestPathFromSingleSource() {
printf("You have chosen to find the shortest path from a single source.\n");
// TODO: 实现求单源最短路径的功能
}
void findAllPairsShortestPath() {
printf("You have chosen to find all pairs shortest path.\n");
// TODO: 实现求每对顶点之间的最短路径的功能
}
int main() {
int choice1, choice2;
while (1) {
printf("Please choose a category:\n");
printf("1. Undirected Graph\n");
printf("2. Undirected Network\n");
printf("3. Directed Graph\n");
printf("4. Directed Network\n");
printf("0. Exit\n");
choice1 = getch() - '0';
printf("%d\n", choice1);
if (choice1 == 0) {
break;
} else if (choice1 < 1 || choice1 > 4) {
printf("Invalid choice.\n");
continue;
}
while (1) {
printf("Please choose a function:\n");
switch (choice1) {
case 1:
printf("1. Create by adjacency matrix\n");
printf("2. Create by adjacency list\n");
printf("3. Traverse by depth-first search\n");
printf("4. Traverse by breadth-first search\n");
break;
case 2:
printf("1. Create by adjacency matrix\n");
printf("2. Create by adjacency list\n");
printf("3. Find minimum spanning tree\n");
break;
case 3:
printf("1. Create by adjacency matrix\n");
printf("2. Create by adjacency list\n");
printf("3. Topological sort\n");
break;
case 4:
printf("1. Create by adjacency matrix\n");
printf("2. Create by adjacency list\n");
printf("3. Find critical path\n");
printf("4. Find shortest path from single source\n");
printf("5. Find all pairs shortest path\n");
break;
}
printf("0. Back\n");
choice2 = getch() - '0';
printf("%d\n", choice2);
if (choice2 == 0) {
break;
} else if ((choice1 == 1 && choice2 < 1 || choice2 > 4) ||
(choice1 == 2 && choice2 < 1 || choice2 > 3) ||
(choice1 == 3 && choice2 < 1 || choice2 > 3) ||
(choice1 == 4 && choice2 < 1 || choice2 > 5)) {
printf("Invalid choice.\n");
continue;
}
switch (choice1) {
case 1:
switch (choice2) {
case 1:
createUndirectedGraphByMatrix();
break;
case 2:
createUndirectedGraphByList();
break;
case 3:
traverseUndirectedGraphByDFS();
break;
case 4:
traverseUndirectedGraphByBFS();
break;
}
break;
case 2:
switch (choice2) {
case 1:
createUndirectedNetworkByMatrix();
break;
case 2:
createUndirectedNetworkByList();
break;
case 3:
findMinimumSpanningTree();
break;
}
break;
case 3:
switch (choice2) {
case 1:
createDirectedGraphByMatrix();
break;
case 2:
createDirectedGraphByList();
break;
case 3:
topologicalSort();
break;
}
break;
case 4:
switch (choice2) {
case 1:
createDirectedNetworkByMatrix();
break;
case 2:
createDirectedNetworkByList();
break;
case 3:
findCriticalPath();
break;
case 4:
findShortestPathFromSingleSource();
break;
case 5:
findAllPairsShortestPath();
break;
}
break;
}
}
}
return 0;
}
```
阅读全文