📄 listnode.h
字号:
#ifndef LIST_NODE_CLASS
#define LIST_NODE_CLASS
#include <fstream.h>
template <class Type>
class LinkedList; // 前视声明
template <class Type>
class ListNode
{
friend class LinkedList<Type>; // 友元类声明
private:
ListNode<Type>* link;
public:
Type data;
ListNode(const Type& item, ListNode<Type>* next = NULL)
:data(item), link(next)
{}
// 向屏幕输出结点的值
friend ostream& operator << (ostream& os,
const ListNode<Type>& node);
// 向文件输出结点的数据值
friend ofstream& operator << (ofstream& ofs,
const ListNode<Type>& node);
friend ostream& operator << (ostream& os,
const LinkedList<Type>& list);
friend ofstream& operator << (ofstream& ofs,
const LinkedList<Type>& list);
};
template <class Type>
ostream& operator << (ostream& os, const ListNode<Type>& node)
{
os << setw(20) << "current node: " << &node << endl
<< node.data
<< setw(20) << "next node: " << node.link << endl;
return os;
}
template <class Type>
ofstream& operator << (ofstream& ofs, const ListNode<Type>& node)
{
ofs<<"**************************************"<<endl;
ofs << node.data << endl;
return ofs;
}
#endif // LIST_NODE_CLASS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -