#pragma once
using namespace std;
template<class ty>
class Orders
{
public:
Orders(int max)
{
this->Arr = new ty[max];
this->Cursize = 0;
this->Maxsize = max;
}
void Add(ty x);
void print();
void deletes(ty x);
~Orders()
{
delete[] this->Arr;
this->Arr = nullptr;
}
ty* Arr;
int Maxsize;
int Cursize;
};
template<class ty>
inline void Orders<ty>::Add(ty x)
{
if (this->Cursize == this->Maxsize) return;
this->Arr[this->Cursize] = x;
this->Cursize++;
}
template<class ty>
inline void Orders<ty>::print()
{
for (int i = 0; i <Cursize; i++)
{
cout << this->Arr[i] << " ";
}
cout << endl;
}
template<class ty>
inline void Orders<ty>::deletes(ty x)
{
for (int i = 0; i < Cursize; i++)
{
if (this->Arr[i] == x)
{
for (int j = i; j < Cursize; j++)
{
this->Arr[j] = this->Arr[j + 1];
}
}
}
Cursize--;
}
自写顺序表
最新推荐文章于 2024-08-06 20:47:49 发布