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

📄 yizhiliangbiao.txt

📁 异质链表基本功能
💻 TXT
字号:
// linklist.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include"iostream"
#include"string"
using namespace std;
class node
{
public:
	node* next;
	node(){next=NULL;}
	virtual void show()=0;
	virtual ~node()
	{}
};

class int_node:public node
{
public:
	int val;
	int_node(int value)
	{val=value;
	}
	void show(){cout<<val<<endl;}
	~int_node(){cout<<"int node is delting"<<endl;}
};
class char_node:public node
{
public:
	char val;
	char_node(char value)
	{val=value;
	}
	void show(){cout<<val<<endl;}
	~char_node(){cout<<"char_node is deleting"<<endl;}
};
class string_node:public node
{
public:
	string val;
	string_node(string value)
	{val=value;
	}
	void show(){cout<<val<<endl;}
	~string_node(){cout<<"string_node is delting"<<endl;}
};
class Header
{
public:
	node* ptr;

	Header(){ptr=NULL;}
	bool incert(node* p)
	{	node* q;

		if(ptr==NULL)
			ptr=p;
		else
		{
			q=ptr;
			while(q->next!=NULL)
				q=q->next;
			q->next=p;
		}
		return 0;
	}
	void display()
	{
		cout<<"遍历节点"<<endl;
		node*q;
		q=ptr;
		while(q!=NULL)
		{
			
			q->show();
		q=q->next;
		}
	}
bool omit(node* p)
{
	node* q;
	node* r=NULL;
	q=ptr;
	while(q!=p)
	{r=q;
		q=q->next;
	}
	if(r==NULL)
	ptr=q->next;
	else r->next=q->next;
	cout<<"删除节点,值为";
	p->show();
	delete p;
	
return 0;
}
	bool search(node* p)
	{
		node* q;
		q=ptr;
		while(q!=p)
			q=q->next;
if(q!=NULL)
{
	cout<<"找到节点值为:"<<endl;
	q->show();
	return 0;
}
return 1;
	}

};
void main()
{	Header head;
	int_node* p=new int_node(10);
	char_node* q=new char_node('a');
	string_node* r=new string_node("string node");
	head.incert(p);
	head.incert(q);
	head.incert(r);
	head.display();
	head.omit (p);
	head.display();
	head.search(q);
	system("pause");
}

⌨️ 快捷键说明

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