FindNode函数测试通过

重命名形参,避免和全局变量冲突
This commit is contained in:
jackfiled 2022-05-18 17:31:34 +08:00
parent 53b9d47f3c
commit 6d97591b1d
3 changed files with 20 additions and 8 deletions

View File

@ -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);
/**
*

View File

@ -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;

View File

@ -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);
}