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 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制