顺序结构.h
#pragma once
#include<iostream>
using namespace std;
class Myvector
{
public:
Myvector();
//打印vector中的元素
void print();
//尾插法
void m_push_back(int val);
//尾删法
void m_pop_back();
//头插法
void m_push_front(int val);
//头删法
void m_pop_front();
//在某个位置插入(下标法)
void m_insert(int pos, int val);
//在某个位置删除(下标法)
void m_erase(int pos);
//清理vector容器
void clear();
//查找
int m_find(int val);
int * first;//存放第一个元素的地址
int capacity;//容器的容量
int size;//容器中元素的个数
};
Myvector::Myvector()
{
first = new int[4];
capacity = 4;
size = 0;
}
//拷贝函数
void m_copy(int* f, int* n,int size)
{
for (; size > 0; n++,f++, size--)
{
*n = *f;
}
}
//尾插法
void Myvector::m_push_back(int val)
{
if (this->size == this->capacity)
{
int* newvector = new int[this->capacity * 2];//创建一个新的数组是原数组的2倍大小
m_copy(first, newvector, this->size); //将原数组拷贝到新数组上
delete[]first;
th