diff --git a/include/rail.h b/include/rail.h index 8016985..9aa5df0 100644 --- a/include/rail.h +++ b/include/rail.h @@ -37,11 +37,11 @@ extern rail_node_t *rails; /** * 查找指定编号的站点指针 - * @param rails 轨道的头节点地址 + * @param head 轨道的头节点地址 * @param id 需要查找的站点编号 * @return 需要查找站点指针 */ -rail_node_t *FindNode(rail_node_t *rails, int id); +rail_node_t *FindNode(rail_node_t *head, int id); /** * 创建轨道列表 diff --git a/src/rail.c b/src/rail.c index bd8d8a1..3c12e72 100644 --- a/src/rail.c +++ b/src/rail.c @@ -41,18 +41,18 @@ rail_node_t *CreateRails(int length, int node_num) return head; } -rail_node_t *FindNode(rail_node_t *rails, int id) +rail_node_t *FindNode(rail_node_t *head, int id) { rail_node_t *p = NULL; - if(rails) + if(head) { - if(rails->id == id) + if(head->id == id) { - return rails; + return head; } - if(rails->next_node != NULL) + if(head->next_node != NULL) { - p = FindNode(rails->next_node, id); + p = FindNode(head->next_node, id); if(p) { return p; diff --git a/test/rail_test.cpp b/test/rail_test.cpp index d30b3f1..b3170f8 100644 --- a/test/rail_test.cpp +++ b/test/rail_test.cpp @@ -38,6 +38,18 @@ TEST(rail, CreateRails) } } +TEST(rail, FindNode) +{ + rail_node_t *head = CreateRails(10, 10); + rail_node_t *p = nullptr; + + p = FindNode(head, 3); + EXPECT_EQ(p->id, 3); + + p = FindNode(head, 9); + EXPECT_EQ(p->id, 9); +} +