using namespace std;
enum errorcode {success,overflaw,underflaw,out};
const max_size =5;
template
class list
{
private:
r l[max_size];
int length;
public:
list();
void print() const;
bool is_empty() const;
bool is_full()const;
void add_begin(r el);
bool add_end(r el);
errorcode add_pos(r el,int pos);
errorcode delete_begin();
errorcode delete_end();
errorcode delete_pos(int pos);
errorcode delete_el(r el);
int search(r el) const;
void sort();
};
template
list
{
length=0;
}
template
void list
{
for(int i=0;i
template
bool list
{
return (length==0);
}
template
bool list
{
return (length==max_size);
}
template
void list
{
if(is_full())
{
cout<<"Overflaw"<
}
for(int i=length-1;i>=0;i--)
l[i+1]=l[i];
l[0]=el;
length++;
}
template
bool list
{
if(is_full())
return false;
l[length]=el;
length++;
return true;
}
template
errorcode list
{
if(is_full())
return overflaw;
if(pos<0>length)
return out;
for(int i=length-1;i>=pos;i--)
l[i+1]=l[i];
l[pos]=el;
length++;
return success;
}
template
errorcode list
{
if(is_empty())
return underflaw;
for(int i=1;i
length--;
return success;
}
template
errorcode list
{
if(is_empty())
return underflaw;
length--;
return success;
}
template
errorcode list
{
if(is_empty())
return underflaw;
if(pos<0>length-1)
return out;
for(int i=pos+1;i
length--;
return success;
}
template
errorcode list
{
if(is_empty())
return underflaw;
int p=search(el);
if(p==-1)
return out;
delete_pos(p);
return success;
}
template
int list
{
for(int i=0;i
return i;
return -1;
}
template
void list
{
for(int i=0;i
{
r t;
t=l[j];
l[j]=l[j+1];
l[j+1]=t;
}
}
void main()
{
list
l.print();
cout<
l.add_begin(2);
l.add_begin(3);
l.print();
cout<
cout<
/* l.add_begin(6);
l.print();
l.delete_begin();
l.print();
l.delete_end();
l.print();
l.delete_pos(1);
l.print();
cout<
l.print();
cout<
*/
l.sort();
l.print();
list
l2.add_begin('a');
l2.print();
}

No comments:
Post a Comment