add: 添加实训 '数据结构课程设计'
This commit is contained in:
49
PracticalTrain/DataStructure/include/graph.h
Normal file
49
PracticalTrain/DataStructure/include/graph.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// include/graph.h
|
||||
#ifndef GRAPH_H
|
||||
#define GRAPH_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "station.h"
|
||||
#include "route.h"
|
||||
|
||||
// 邻接表节点
|
||||
typedef struct AdjNode {
|
||||
int stationId;
|
||||
int routeId;
|
||||
double travelTime; // 行驶时间(分钟)
|
||||
struct AdjNode* next;
|
||||
} AdjNode;
|
||||
|
||||
// 邻接表
|
||||
typedef struct AdjList {
|
||||
AdjNode* head;
|
||||
} AdjList;
|
||||
|
||||
// 图结构
|
||||
typedef struct Graph {
|
||||
AdjList adjLists[MAX_STATIONS];
|
||||
int vertexCount;
|
||||
} Graph;
|
||||
|
||||
// 路径节点
|
||||
typedef struct PathNode {
|
||||
int stationId;
|
||||
int routeId;
|
||||
double time;
|
||||
struct PathNode* next;
|
||||
} PathNode;
|
||||
|
||||
// 图操作函数
|
||||
Graph* createGraph(int vertexCount);
|
||||
void destroyGraph(Graph* graph);
|
||||
void addEdge(Graph* graph, int from, int to, int routeId, double travelTime);
|
||||
void buildGraphFromRoutes(Graph* graph, const BusRoute routes[], int routeCount,
|
||||
const Station stations[], int stationCount);
|
||||
|
||||
// 路径查询函数
|
||||
PathNode* dijkstra(Graph* graph, int start, int end, double* totalTime);
|
||||
void freePath(PathNode* path);
|
||||
void displayPath(PathNode* path, const Station stations[], int stationCount,
|
||||
const BusRoute routes[], int routeCount);
|
||||
|
||||
#endif
|
||||
22
PracticalTrain/DataStructure/include/route.h
Normal file
22
PracticalTrain/DataStructure/include/route.h
Normal file
@@ -0,0 +1,22 @@
|
||||
// include/route.h
|
||||
#ifndef ROUTE_H
|
||||
#define ROUTE_H
|
||||
|
||||
#include "station.h"
|
||||
|
||||
#define MAX_STATIONS_PER_ROUTE 50
|
||||
|
||||
typedef struct BusRoute {
|
||||
int id;
|
||||
char routeName[50];
|
||||
int stationCount;
|
||||
int stations[MAX_STATIONS_PER_ROUTE]; // 站点ID序列
|
||||
double segmentTimes[MAX_STATIONS_PER_ROUTE]; // 每段行驶时间(分钟)
|
||||
} BusRoute;
|
||||
|
||||
// 线路管理函数
|
||||
int loadRoutes(const char* filename, BusRoute routes[], int maxRoutes);
|
||||
void displayRoute(const BusRoute* route, const Station stations[], int stationCount);
|
||||
void displayAllRoutes(const BusRoute routes[], int routeCount, const Station stations[], int stationCount);
|
||||
|
||||
#endif
|
||||
23
PracticalTrain/DataStructure/include/station.h
Normal file
23
PracticalTrain/DataStructure/include/station.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// include/station.h
|
||||
#ifndef STATION_H
|
||||
#define STATION_H
|
||||
|
||||
#define MAX_NAME 50
|
||||
#define MAX_STATIONS 100
|
||||
|
||||
typedef struct Station {
|
||||
int id;
|
||||
char name[MAX_NAME];
|
||||
double latitude;
|
||||
double longitude;
|
||||
int stopTime; // 停靠时间(秒)
|
||||
} Station;
|
||||
|
||||
// 站点管理函数
|
||||
int loadStations(const char* filename, Station stations[], int maxStations);
|
||||
int findStationByName(const Station stations[], int count, const char* name);
|
||||
int findStationById(const Station stations[], int count, int id);
|
||||
void displayStation(const Station* station);
|
||||
void displayAllStations(const Station stations[], int count);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user