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

📄 set.h

📁 jedit 一个小型java编译器的源码
💻 H
字号:
#ifndef SET_H
#define SET_H
#include "vector.h"
#include <assert.h>
template<class Type>
class set
{
	vector<Type> elem;
	int max;
	int lastindex;
	int within(const Type& e)
	{
		for(lastindex=0;lastindex<max;lastindex++)
			if(elem[lastindex]->operator==(e))
				return lastindex;
		return -1;
	}
	void operator=(set&);
	set(set&);
public:
	set()
	{
		max=0;
		lastindex=0;
	}
	void empty();
	void add(const Type&);
	int contains(const Type&);
	int index(const Type&);
	Type& operator[](int index)
	{
//		if(index<0||index>=max)
//			index=1;
//		assert(index>=0&&index<max);
		return *elem[index];
	}
	int length() const
	{
		return max;
	}
	void SetMax(int Max){max=Max;}
};

template<class Type>void
set<Type>::add(const Type& e)
{
	if(!contains(e))
	{
		elem[max]=new Type(e);
		max++;
	}
}
template<class Type>void
set<Type>::empty()
{
	for(lastindex=0;lastindex<max;lastindex++)
		delete elem[lastindex];
	max=0;
}

template<class Type> int
set<Type>::contains(const Type& e)
{
	return within(e)!=-1;
}

template<class Type> int
set<Type>::index(const Type& e)
{
	if(elem[lastindex]->operator!=(e))
	{
		int ind=within(e);
		assert(ind!=-1);
	}
	return lastindex;
}
#endif

⌨️ 快捷键说明

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