list.h

来自「应用斐波纳契堆和邻接表改进单源最短路径算法」· C头文件 代码 · 共 71 行

H
71
字号
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////CLASS LIST//////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

template <class Type> class List;
class Node{
	friend class Graph;		
public:
	Node(){Id=Length=0;};
	Node(const int v,const int length){
		Id=v;
		Length=length;
	};
private:
	int Id;
	int Length;
};

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////LISTNODEDEFINE//////////////////////////////////////////////////////////
template <class Type>
class ListNode{
	friend class List;
	friend class Graph;
private:
	Type Data;
public:
	ListNode *link;
	ListNode(){link=0;};
	ListNode(const int v,const int length):Data(v,length){link=0;};
};

//////////////////////////////////////////////////////////////////////////////////
////////////////////////////LISTDEFINE/////////////////////////////////////////////
template <class Type>
class List
{
	friend class Graph;
public:
	List(){
		first=0;
	first=NULL;
	};
	void Insert(const int v,const int length);
	~List();
private:
	ListNode<Type> *first;
};

////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////INSERT///////////////////////////////////////////////
template <class Type>
void List<Type>::Insert(const int v,const int length)
{
	ListNode<Type> *p=new ListNode<Type>(v,length);
	ListNode<Type> *ps=first;
	first=p;
	p->link=ps;
	p=ps=0;
}
/////////////////////////////////////////////////////////////////////////////////////
template <class Type>
List<Type>::~List()
{
	ListNode<Type> *ps=0;
	for(ListNode<Type> *p=first;p;p=ps)
	{   
		ps=p->link;
		delete p;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?