一个简单的C++顺序表

#include
using namespace std;
template < typename datatype > class seqlist
{
	public:
		seqlist(int size=defaultsize){
			if(size>0)
			{
				maxsize=size;
				length=0;
				elements=new datatype[maxsize];
				for(int i=0;i bool seqlist ::insertelement (datatype data)
{
	int currentindex=length;
	if(length>=maxsize) return false;
	else{
		elements[currentindex]=data;
		length++;
		return true;
	}
}

template < typename datatype > datatype seqlist::getelement (int location)
{
	if(location <0 || location >= length ) {cout<<"参数无效"< bool seqlist::deleteelement(int location)
{
	if(location <0 || location >= length ) return false;
	else
	{
		for(int i=location;i bool seqlist::changeelement(int location,datatype newdata)
{
	if(location<0 || location>=length) return false;
	else
	{
		elements[location]=newdata;
		return true;
	}
}

int main()
{
	seqlist list(10);
	for(int i=0;i<10;i++)  list.insertelement(i*10);
	for(int i=0;i

你可能感兴趣的:(一个简单的C++顺序表)