[C ++]線形テーブルの擬似アルゴリズム

#pragma once
class list
{
    
    
private:
	int arrayLength;//最大长度
	int listSize;//实际长度
	int* num;//动态数组
	void checkSize(int index)const;

public:
	list(int initialCapacity = 10);
	list(const list&);
	~list();

	bool empty()const;//判断是否为空
	bool size()const;//返回长度
	int& get(int theIndex)const;
	int indexOf(const int& theElement)const;
	void erase(int theIndex)const;
	void insert(int theIndex, const int& theElement);
	void output()const;//输出
};

void list::checkSize(int index) const
{
    
    
	/*
		如果索引小于0或大于等于实际长度
		抛出异常
	*/
}

list::list(int initialCapacity)
{
    
    
	/*
	*
	*	如果initialCapacity小于0,
	*	即最大长度小于0,抛出异常
	*
		进行初始化操作
		最大长度 = initialCapacity
		动态数组申请动态内存空间
		有效长度 = 0
	*/
}

list::~list()
{
    
    	/*
	删除动态数组
	*/
}

int& list::get(int theIndex) const
{
    
    	/*
	判断索引是否正常checkIndex(theIndex)
	*/
	// TODO: 在此处插入 return 语句
}

int list::indexOf(const int& theElement) const
{
    
    	/*
	当该数组不存在元素时,返回-1
	*/
	return 0;
}

void list::erase(int theIndex) const
{
    
    
	/*
	先判断索引是否正常checkIndex(theIndex)
	*/
}

void list::insert(int theIndex, const int& theElement)
{
    
    
	/*
	首先判断索引正常
	如果索引小于0或大于实际长度
	则抛出异常。
	注意:等于实际长度即追加
	*/
}


おすすめ

転載: blog.csdn.net/weixin_48180029/article/details/113665426
おすすめ