C ++中的链表问题

时间:2014-10-01 03:37:42

标签: c++ linked-list

我首先尝试创建一个节点,但我不确定它是否正确。对不起,我是C ++的新手。我不知道如何让我的节点p指向链表的第一个元素。希望能提供帮助。感谢

这是我的功能:

template<class Type>
void longestSequence(linkedListType<Type>& list, int& maxCount, Type& value)
{
    nodeType<Type> *p = first;
    int count = 0;
    int tempValue = 0;
    while(p != NULL)
    {
        if(p->info == p->link->info)
        {
            count++;
            tempValue = p->info;
        } 
        p = p->link;
    } 
    if(count > maxCount)
    {
        maxCount = count;
        value = tempValue;
    }
    else if(count == maxCount && tempValue < value)
    {
        value = tempValue;
    }
}

1 个答案:

答案 0 :(得分:0)

您的班级linkedListType<Type>应该有一名成员nodeType<Type>* head 创建链接列表的第一个节点时,应将其地址分配给head

然后,您可以随时访问链接列表的第一个节点 例如,nodeType<Type> *p = list.head