Лабораторная работа 1 / CL_CLIST_CPP
.doc//file: cl_clist.cpp
//description: class "list of elem"
//author: Baranova N.N. 3351
//date: 18.02.06 ver:1
#include <Cl_CList.h>
CList::CList(CElem *cur0,CElem *head0)
{
cout<<"Run list constructor"<<endl;
set_cur(cur0);
set_head(head0);
cout<<"New list"<<endl<<endl;
}
CList :: ~CList()
{
cout<<"Run list destructor"<<endl;
GoBOL();
while (EOList()!=1)
{
CElem *tmp;
tmp=head;
head=head->get_next();
cur=head;
tmp->set_next(NULL);
delete (tmp);
}
cout<<"list delete"<<endl<<endl;
}
int CList :: NullList()
{
if (get_head()==NULL) return 1;
else return 0;
}
int CList :: EOList()
{
if( (get_cur()==NULL)||(NullList()) )return 1;
else return 0;
}
void CList :: set_head (CElem *head0)
{
head=head0;
}
CElem * CList :: get_head()
{
return head;
}
void CList :: set_cur (CElem *cur0)
{
cur=cur0;
}
CElem * CList :: get_cur()
{
return cur;
}
void CList :: GoBOL()
{
set_cur(get_head());
}
void CList :: GoNext()
{
set_cur(get_cur()->get_next());
}
void CList :: InsToNull (CElem *elem0)
{
set_head(elem0);
set_cur(elem0);
}
void CList :: Insert (CElem *elem0)
{
if (NullList()==1) InsToNull(elem0);
else
{
GoBOL();
while (get_cur()->get_next()!=NULL) GoNext();
get_cur()->set_next(elem0);
set_cur(get_cur()->get_next());
}
}
/* CElem* CList::Search(int val0)
{
GoBOL();
while (EOList()!=1)
{
if (get_cur()->get_val()!=val0)
GoNext();
else return get_cur();
}
return NULL;
} */
void CList :: PrintList()
{
GoBOL();
if (NullList()) cout<<"List is empty"<<endl;
else
{
while (EOList()!=1)
{
cout<<get_cur()->get_val()<<" ";
GoNext();
}
}//else
}