# 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;
}
}