重新整理了代码

This commit is contained in:
jackfiled 2022-06-05 20:56:44 +08:00
parent 6e79af8b06
commit 9b4f84f378
7 changed files with 28 additions and 50 deletions

View File

@ -223,6 +223,7 @@ int main()
// 没到站的话那就走吧 // 没到站的话那就走吧
RunBus(direction); RunBus(direction);
} }
break;
default: default:
// 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支 // 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支
break; break;

View File

@ -1,4 +1,3 @@
from email.encoders import encode_noop
import os import os
path = "SSTF/" path = "SSTF/"
@ -9,7 +8,7 @@ out_path = path + "{}.out"
dict_file = open(dict_path, "r", encoding="utf8") dict_file = open(dict_path, "r", encoding="utf8")
dict_str = dict_file.read() dict_str = dict_file.read()
dict_file.close(); dict_file.close()
for i in range(1, 11): for i in range(1, 11):
dir_path = "{}/".format(i + 7) dir_path = "{}/".format(i + 7)
@ -36,4 +35,3 @@ for i in range(1, 11):
output_file.close() output_file.close()
dict_file.close() dict_file.close()

View File

@ -72,18 +72,4 @@ int SCANDirection(bus_query_t *query, int orientation);
*/ */
bus_query_t *SCANBTWQuery(); bus_query_t *SCANBTWQuery();
/** #endif //AUTO_PILOT_BUS_CONTROLLER_H
* FCFS策略的控制函数
*/
void FCFSControl();
/**
* SSTF策略的控制函数
*/
void SSTFControl();
/**
* SCAN策略的控制函数
*/
void SCANControl();
#endif //AUTO_PILOT_BUS_CONTROLLER_H

1
main.c
View File

@ -193,6 +193,7 @@ int main()
// 没到站的话那就走吧 // 没到站的话那就走吧
RunBus(direction); RunBus(direction);
} }
break;
default: default:
// 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支 // 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支
break; break;

View File

@ -8,7 +8,9 @@ int ReadInput(char *inputString)
char src[20]; char src[20];
int num; int num;
sscanf(inputString, "%[a-z] %d", src, &num); sscanf(inputString, "%[a-z] %d", src, &num);
if (0 == strcmp("clock", src)) if (0 == strcmp("clock", src))
{ {
return IO_CLOCK; return IO_CLOCK;
@ -83,6 +85,7 @@ rail_node_t *ReadConfigFile()
case 'S': case 'S':
// STRATEGY // STRATEGY
p = buffer; p = buffer;
// 将=前的字符全部略去 // 将=前的字符全部略去
while (*p != '=') while (*p != '=')
{ {
@ -134,7 +137,6 @@ rail_node_t *ReadConfigFile()
default: default:
continue; continue;
} }
} }
// 处理参数去缺省值的情况 // 处理参数去缺省值的情况
@ -169,6 +171,7 @@ void PrintState()
clockwise[count] = '0'; clockwise[count] = '0';
counterclockwise[count] = '0'; counterclockwise[count] = '0';
} //遍历轨道链表将所有站点初始化为0无任何请求 } //遍历轨道链表将所有站点初始化为0无任何请求
// 在字符串的末尾填0
target[count] = '\0'; target[count] = '\0';
clockwise[count] = '\0'; clockwise[count] = '\0';
counterclockwise[count] = '\0'; counterclockwise[count] = '\0';
@ -216,6 +219,7 @@ void PrintStateInner(char *str)
clockwise[count] = '0'; clockwise[count] = '0';
counterclockwise[count] = '0'; counterclockwise[count] = '0';
} //遍历轨道链表将所有站点初始化为0无任何请求 } //遍历轨道链表将所有站点初始化为0无任何请求
// 在字符串的末尾填0
target[count] = '\0'; target[count] = '\0';
clockwise[count] = '\0'; clockwise[count] = '\0';
counterclockwise[count] = '\0'; counterclockwise[count] = '\0';

View File

@ -283,19 +283,4 @@ bus_query_t *SCANBTWQuery()
}//遍历请求链表,判断是否有可以顺便处理的请求 }//遍历请求链表,判断是否有可以顺便处理的请求
return NULL; return NULL;
}
void FCFSControl()
{
}
void SSTFControl()
{
}
void SCANControl()
{
} }

View File

@ -40,24 +40,27 @@ rail_node_t *CreateRails(int length, int node_num)
rail_node_t *FindNode(rail_node_t *head, int id) rail_node_t *FindNode(rail_node_t *head, int id)
{ {
rail_node_t *p = NULL; // 排除头节点为空的情况
if(head) if(head == NULL)
{ {
if(head->id == id) return NULL;
{
return head;
}
if(head->next_node != NULL)
{
p = FindNode(head->next_node, id);
if(p)
{
return p;
}
}
} }
return NULL;
rail_node_t *result = NULL;
rail_node_t *p = head;
do
{
if(p->id == id)
{
result = p;
break;
}
p = p->next_node;
}
while (p != head);
return result;
} }
void FreeRails(rail_node_t *head) void FreeRails(rail_node_t *head)