7-24作业

思维导图

7-24作业_第1张图片

7-24作业_第2张图片 

 

#include
#include
#include
#include
using namespace std;

template
class Myvetor
{
public:
	
	Myvetor() :first(nullptr), last(nullptr), end(nullptr)//构造函数
	{

	}
	~Myvetor()//析构函数
	{
		delete[] first;
	}
	int size()const;//数组大小
	Myvetor(const Myvetor& other)//拷贝构造
	{
		int size = other.size();
		first = new T[size];
		last = first + size;
		end = last;
	}
	Myvetor& operator=(const Myvetor& other)//拷贝赋值
	{
		int size = other.size();
		first = new T[size];
		last = first + size;
		end = last;
		std::copy(other.first, other.last, first);
	}
	T& at(int index)
	{
		if (index<0||index>size())
		{
			cout << "不在这个范围" << endl;
		}
		return first[index];
	}//查找
	bool empty()
	{
		return size() == 0;
	}//判空
	bool full()
	{
		return size() == (end-first);
	}//判满
	T& front()
	{
		return *first;
	}//返回第一个
	void clear()
	{
		
		last = first;
	}//清理
	void expand()
	{
		int num = size() * 2;
		T* newfirst = new T[num];
		T* newlast = newfirst+size();
		T* newend = newfirst + size();
		for (int i = 0; i 
int Myvetor::size() const
{
	return last - first;
}//长度

int main()
{

}

你可能感兴趣的:(算法,c++)