alexsendar 2015-06-16 12:09 采纳率: 100%
浏览 2031

学数据结构是一个叫殷人昆写的,书里各种bug,下面的重载函数到底怎么写?不要+内容,只要重载格式

#ifndef SORTEDCHAIN_INCLUDED
#define SORTEDCHAIN_INCLUDED
#include
#include
using namespace std;

template
struct ChainNode
{ E data;
ChainNode* link;
ChainNode(): link(NULL){};
ChainNode(E& e1, ChainNode* next = NULL): data(e1), link(next) {}
};

template
class SortedChain
{
public:
SortedChain()
{ first = new ChainNode;
assert(first != NULL);
}
~SortedChain(){delete first;};
void Insert(const K k1, E& e1);
LinkedSet& operator + (LinkedSet& s2);
private:
ChainNode* first;
};

template
void SortedChain::Insert(const K k1, E& e1)
{ ChainNode* p = first->link, * pre = first, * newNode;
while (p != NULL && p->data < k1)
{ pre = p; p = p->link;
}
if( p != NULL && p->data == k1)
{p->data = e1; return;}
newNode = new ChainNode(e1);
if (newNode == NULL) {cout<<"memeory assign failed"< newNode->link = p; pre->link = newNode;
}
template
LinkedSet& LinkedSet::operator + (LinkedSet& s2)
{

}
#endif // SORTEDCHAIN_INCLUDED
#include
#include
#include "SortedChain"
int main()
{
SortedChain l1, l2;
return 0;
}

  • 写回答

2条回答

  • 知常曰明 2015-06-16 12:22
    关注

    用归并排序把s2插进本链表中。

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?