#include <iostream.h>
#include <stdlib.h>
const int MaxListSize = 50;
typedef int DataType;
class SeqList
{
private:
DataType listitem[MaxListSize];
int size;
public:
SeqList(void);
//the method of access elements
int ListSize(void) const;
int ListEmpty(void) const;
int Find(DataType& item) const;
DataType GetData(int pos) const;
//the method of modify elements
void Insert(const DataType& item);
void Delete(const DataType& item);
DataType DeleteFront(void);
void ClearList(void);
};
void PrintList(const SeqList& L)
{
int length = L.ListSize();
for (int i = 0; i < length; i++)
{
cout << L.GetData(i) << " ";
}
cout << endl;
}
void InsertMax(SeqList& L, int elt)
{
int i = 0;
while (i < L.ListSize() && L.GetData(i) < elt)
{
i++;
}
if (i != L.ListSize())
{
cout << "not insert" << endl;
}
else
{
L.Insert(elt);
}
}
//Constructor.
SeqList::SeqList()
{
size = 0;
}
void SeqList::Insert(const DataType& item)
{
if ((size + 1) > MaxListSize)
{
cerr << "maxinum list size exceeded" << endl;
exit(1);
}
listitem[size++] = item;
}
void SeqList::Delete(const DataType& item)
{
int i = 0;
while (i < size && !(item == listitem[i]))
{
i++;
}
if (i < size)
{
while (i < size - 1)
{
listitem[i] = listitem[i + 1];
i++;
}
size--;
}
}
DataType SeqList::GetData(int pos) const
{
if (pos < 0 || pos >=size)
{
cerr << "pos is out of range!" << endl;
exit(1);
}
return listitem[pos];
}
int SeqList::Find(DataType& item) const
{
int i = 0;
if (ListEmpty())
{
return 0;
}
while (i < size && !(item == listitem[i]))
{
i++;
}
if (i < size)
{
item = listitem[i];
return 1;
}
else
{
return 0;
}
}