⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linkedlist.h

📁 linked_list的简单实现 数据结构的经典问题
💻 H
字号:
#include <iostream>
using namespace std;
enum{kissmaller,kislarger,kissame};

/*
Data class to put into the linked list
Any class in this linked list must support two methods:
Compare
*/

class Data
{
public:
	Data(int val):myValue(val){}
	~Data(){}
	int Compare(const Data&);
	void Show(){cout<<myValue<<endl;}
private:
	int myValue;
};

class Node;
class HeadNode;
class TailNode;
class InternalNode;

class Node
{
public:
	Node()
	{}
	virtual ~Node(){}
	virtual Node* Insert(Data* theData)=0;
	virtual void Show()=0;
private:
};

//This is the node which holds the actual object
//In this case the object is of type Data
//We'll see how to make this more general when

class InternalNode: public Node
{
public:
	InternalNode(Data* theData,Node* next);
	~InternalNode(){delete myNext;delete myData;}
	virtual Node* Insert(Data* theData);
	virtual void Show(){myData->Show();myNext->Show();}
private:
	Data* myData;//the data itself
	Node* myNext;//points to next node in the linked list
};

class TailNode: public Node
{
public:
	TailNode(){}
	~TailNode(){}
	virtual Node* Insert(Data* theData);
	virtual void Show(){}
private:
};
// head node has no data,it just points to the very beginning of the list
class HeadNode: public Node
{
public:
	HeadNode();
	~HeadNode(){delete myNext;}
	virtual Node* Insert(Data* theData);
	virtual void Show(){myNext->Show();}
private:
	Node *myNext;
};

class LinkedList
{
public:
	LinkedList();
	~LinkedList()
	{
		delete myHead;
	}
	void Insert(Data* theData);
	void ShowAll(){myHead->Show();}
private:
	HeadNode* myHead;
};

⌨️ 快捷键说明

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