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

📄 exam1.h

📁 森林的层次遍历、广义表输出等关于森林的一些基本操作
💻 H
字号:
#include <iostream>
using namespace std;
template<class T>
struct node{
	T data;
	node<T>* next;
};
template<class T>
class List{
public:
    List();									//构造函数
	node<T>* get_point(int);				//求第i个结点
	int InsElem(node<T>*,T);				//在某结点后前插入x
	int Insert(T);							//在链表结尾插入x 
	node<T>* head;							//头指针
};
template<class T>
List<T>::List(){							//构造函数
	head=new node<T>;
	head->next=NULL;
}
template<class T>
node<T>* List<T>::get_point(int i)	//求第i个结点
{
	node<T> *p;
	int j=1;
	p=head;
	while(j<i&&p!=NULL){
		p=p->next;
		j++;
	}
	return p;
}
template<class T>
int List<T>::InsElem(node<T>* p,T x)	//在某结点后插入x
{
	node<T>* s;
	s=new node<T>;
	s->data=x;
	s->next=p->next;
	p->next=s;
	return 1;
}
template<class T>
int List<T>::Insert(T x)	//在链表结尾插入x
{
	node<T> *s,*p;
	p=head;
	while(p->next!=NULL)
	{
		p=p->next;
	}
	s=new node<T>;
	s->data=x;
	s->next=p->next;
	p->next=s;
	return 1;
}

⌨️ 快捷键说明

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