bool CharacterList::addCharacter(Character *newCharacter)
{
Character *temp, *back;
if(head == NULL)
{
head = newCharacter;
}
else
{
temp = head;
back = NULL;
while((temp != NULL) && (temp < newCharacter))
{
back = temp;
temp = temp.next;
}
if(back == NULL)
{
newCharacter.next = head;
head = newCharacter;
}
else
{
back.next = newCharacter;
newCharacter.next = temp;
}
return true;
}
}
我为类Character的对象创建有序链表(CharacterList)。此函数只接受一个参数,一个指向Character类对象(* newCharacter)的指针。然后,它会将此字符添加到角色对象的链接列表中。我不确定这是否是我将对象插入链表的方式。有人可以指导我吗?
答案 0 :(得分:3)