添加了求与请求距离的函数

添加了表示整个轨道长度的全局变量
This commit is contained in:
2022-06-03 21:28:52 +08:00
parent 7e0afb9990
commit 3b6d7933a7
6 changed files with 42 additions and 4 deletions

View File

@@ -82,4 +82,30 @@ int JudgeOnStation()
{
return BUS_FAlSE;
}
}
int GetQueryDistance(bus_query_t *query, int orientation)
{
rail_node_t *target_node = query->node;
rail_node_t *now_node = the_bus->rail_node_pos;
int distance = 0;
if(orientation == BUS_CLOCK_WISE)
{
while (now_node != target_node)
{
distance += now_node->next_node_distance;
now_node = now_node->next_node;
}
}
else if(orientation == BUS_COUNTER_CLOCK_WISE)
{
while (now_node != target_node)
{
distance += now_node->last_node_distance;
now_node = now_node->last_node;
}
}
return distance;
}

View File

@@ -151,6 +151,7 @@ rail_node_t *ReadConfigFile()
chosen_strategy = BUS_FCFS;
}
all_distance = distance * total_station;
rail_node_t *head = CreateRails(distance, total_station);
return head;
}

View File

@@ -2,6 +2,7 @@
rail_node_t *rails = NULL;
int bus_time = 0;
int all_distance = 0;
rail_node_t *CreateRails(int length, int node_num)
{