FindNode函数测试通过
重命名形参,避免和全局变量冲突
This commit is contained in:
parent
53b9d47f3c
commit
6d97591b1d
|
@ -37,11 +37,11 @@ extern rail_node_t *rails;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找指定编号的站点指针
|
* 查找指定编号的站点指针
|
||||||
* @param rails 轨道的头节点地址
|
* @param head 轨道的头节点地址
|
||||||
* @param id 需要查找的站点编号
|
* @param id 需要查找的站点编号
|
||||||
* @return 需要查找站点指针
|
* @return 需要查找站点指针
|
||||||
*/
|
*/
|
||||||
rail_node_t *FindNode(rail_node_t *rails, int id);
|
rail_node_t *FindNode(rail_node_t *head, int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建轨道列表
|
* 创建轨道列表
|
||||||
|
|
12
src/rail.c
12
src/rail.c
|
@ -41,18 +41,18 @@ rail_node_t *CreateRails(int length, int node_num)
|
||||||
return head;
|
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;
|
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)
|
if(p)
|
||||||
{
|
{
|
||||||
return p;
|
return p;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user