陈一丹5 股份的去向:链表的主函数该怎么写啊?类的声明在下面

来源:百度文库 编辑:高考问答 时间:2024/04/19 16:04:48
#include<iostream>
using namespace std;

template<class Type> class List;

template<class Type> class ListNode
{
friend class List<Type>;
public:
//下面,不定义具体内容需要加上 {}
ListNode() {};
ListNode(Type item);
private:
Type data;
ListNode<Type> *link;
};

template<class Type> class List
{
public:
//由于ListNode是模版类,需要添加上模版如下:
List(){last=first=new ListNode<Type>();}
List(Type value){last=first=new ListNode<Type> (value);}
//析构函数也是一样,不定义具体内容需要加上 {}
~List(){};
private:
ListNode<Type> *first,*last;
};

template<class Type> ListNode<Type>::ListNode(Type item)
{
data=item;link=NULL;
}
void main()
{

List<int>list;

}

传说 ADT 是要有操作的说。。。你的链表没操作主函数里当然没什么好写的了。。。