?? link.h
字號:
#ifndef link
#define link
#include "clist.h"
#include "assert.h"
#include"listIterator.h"
template <class T> class listIterator;
template <class T> class list;
template<class T>class link
{
public:
// 插入一個新結點
link<T>*insert(T val);
private:
// 構造函數
link(T linkValue,link<T>*nextPtr);
link(const link<T>&source);
// 復制
link<T>*duplicate()const;
// 數據域
T value;
link<T>* ptrToNextLink;
// 友元
friend class list<T>;
//friend class listlterator<T>;
};
template<class T> link<T>::link(T val,link<T>*nxt)
: value(val),ptrToNextLink(nxt)
{
// 沒有其他操作
}
template<class T> link<T>::link(const link<T> & source)
: value(source.value),ptrToNextLink(source.ptrToNextLink)
{
// 沒有其他動作
}
template<class T> link<T>*link<T>::insert(T val)
{
ptrtonextlink=new link<T>(val,ptrToNextLink);
assert(ptrToNextLink !=0);
return ptrToNextLink;
}
template<class T> link<T>*link<T>::duplicate()const
{
link<T>*newlink;
if(ptrToNextLink!=0)
//當還有下一個結點時遞歸調用復制函數
newlink=
new link<T.(value,ptrToNextLink->duplicate());
else
newlink=new link<T>(value,0);
//檢查動態分配是否成功
assert(newlink !=0);
return newlink;
}
#endif //link
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -