求两个集合的交 出现这个错误怎么解决? error C2955: “SortedList”: 使用类 模板 需要 模板 参数列表
structNode{Typedata;Node<Type>*next;};template<classType>classSortedList{public:Sorte...
struct Node { Type data; Node<Type> *next; };
template <class Type> class SortedList
{ public: SortedList(Type a[],int n );
void Mixedlist(SortedList<Type> &la,SortedList<Type> &lb); //求交
private:
Node<Type> *first; //表头结点指针
};
template <class Type>
void SortedList::Mixedlist(SortedList<Type>&la,SortedList<Type> &lb)
{
Node<Type> *pa,*pb,*p;
pa=new Node<Type>;pb=new Node<Type>;p=new Node<Type>;
pa = la.first->next; pb = lb.first->next, p= NULL;
while( pa->next != NULL && pb!= NULL )
{
if( pa->next->data < pb->data )
{
p = pa->next;
pa->next = p->next;
free( p );
}
else if( pa->next->data > pb->data )
{
pb = pb->next;
}
else
{
pa = pa->next;
pb = pb->next;
}
}
while( pa->next != NULL )
{
p = pa->next;
pa->next = p->next;
free( p );
}
} 展开
template <class Type> class SortedList
{ public: SortedList(Type a[],int n );
void Mixedlist(SortedList<Type> &la,SortedList<Type> &lb); //求交
private:
Node<Type> *first; //表头结点指针
};
template <class Type>
void SortedList::Mixedlist(SortedList<Type>&la,SortedList<Type> &lb)
{
Node<Type> *pa,*pb,*p;
pa=new Node<Type>;pb=new Node<Type>;p=new Node<Type>;
pa = la.first->next; pb = lb.first->next, p= NULL;
while( pa->next != NULL && pb!= NULL )
{
if( pa->next->data < pb->data )
{
p = pa->next;
pa->next = p->next;
free( p );
}
else if( pa->next->data > pb->data )
{
pb = pb->next;
}
else
{
pa = pa->next;
pb = pb->next;
}
}
while( pa->next != NULL )
{
p = pa->next;
pa->next = p->next;
free( p );
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询