두 개의 목록을 참조로 사용하는 혼합 방법을 만들었습니다. 내가 목록 3을 반환하는 것보다 목록 1과 2를 할당하는 혼합 목록 (3)을 만들었습니다.힙에 일치하는 함수가 없습니다.
구현하려고 할 때 스택에서 작동하지만 힙에서는 작동하지 않습니다. 가능한 문제가 있습니까?
(sth3 = sth3-> mix (sth1, sth2);) - 일치하는 함수 문제가 없습니다.
작동하지 :
Sequence<int,string> *sth1 = new Sequence<int,string>();
sth1->AddNode(1,"n1");
sth1->AddNode(2,"n2");
Sequence<int,string> *sth2 = new Sequence<int,string>();
sth2->AddNode(10,"n1");
Sequence<int,string> *sth3 = new Sequence<int,string>();
sth3 = sth3->mix(sth1,sth2);
sth3->Print();
한 작업 :
Sequence<int,string> st1;
st1.AddNode(1,"n1");
Sequence<int,string> st2;
st2.AddNode(10,"n1");
Sequence<int,string> st3;
st3 = st3.mix(st1,st2);
st3.Print();
단순화 된 기능 믹스 (..) 힙 하나에서
template<typename key,typename info>
Sequence<key, info> Sequence<key, info>::mix(const Sequence<key, info> &s1, const Sequence<key,info> &s2)
{
Sequence<key,info> s;
Node<key, info> *curr1 = s1.head;
Node<key, info> *curr2 = s2.head;
while (s.count < 10)
{
s.AddNode(curr1->GetId(), curr1->GetData())
curr1 = curr1->GetNext();
s.AddNode(curr2->GetId(), curr2->GetData())
curr2 = curr2->GetNext();
if (curr1 == NULL && curr2 == NULL)
break;
}
return s;
}
최소한의 예는 달콤 할 것입니다. – gsamaras
@gsamaras 혼합 함수의 단순화 된 구현을 추가했습니다. – sswwqqaa