Скачиваний:
23
Добавлен:
01.05.2014
Размер:
25.09 Кб
Скачать

//file: cl_ccirlist.cpp

//description: class "circle list"

//author: Baranova N.N. 3351

//date:18.02.06. ver: 1

#include <Cl_CCirList.h>

CCirList::CCirList(CElem *cur0,CElem *head0)

{

cout<<"Run circle list constructor"<<endl;

set_curcir(cur0);

set_headcir(head0);

cout<<"New circle list"<<endl<<endl;

}

CCirList :: ~CCirList() //destructor

{

cout<<endl<<"Run circle list destructor"<<endl;

while (EOCirList()!=1) GoNextCir();

while(NullCirList()!=1)

{

CElem *tmp;

tmp=get_headcir();

if (get_curcir()!=get_headcir())

{

curcir->set_next(get_headcir()->get_next());

set_headcir(get_headcir()->get_next());

tmp->set_next(NULL);

delete (tmp);

}

else//delet last elem

{

set_headcir(NULL);

set_curcir(NULL);

delete (tmp);

}

}

cout<<"circle list delete"<<endl<<endl;

}

int CCirList :: NullCirList()

{

if (get_headcir()==NULL) return 1;

else return 0;

}

int CCirList :: EOCirList()

{

if( (get_curcir()->get_next()==get_headcir())||(NullCirList()) )return 1;

else return 0;

}

void CCirList :: set_headcir (CElem *head0)

{

headcir=head0;

}

CElem * CCirList :: get_headcir()

{

return headcir;

}

void CCirList :: set_curcir (CElem *cur0)

{

curcir=cur0;

}

CElem * CCirList :: get_curcir()

{

return curcir;

}

void CCirList :: GoBOLCir()

{

set_curcir(get_headcir());

}

void CCirList :: GoNextCir()

{

set_curcir(get_curcir()->get_next());

}

void CCirList :: GoLastCir()

{

while (EOCirList()!=1) GoNextCir();

}

void CCirList :: InsToNullCir (CElem *elem0)

{

set_headcir(elem0);

set_curcir(elem0);

elem0->set_next(get_headcir());

}

void CCirList :: InsertCirToBegin (CElem * elem0)

{

if (NullCirList()) InsToNullCir(elem0);

else

{

elem0->set_next(get_headcir());

GoLastCir();

set_headcir(elem0);

get_curcir()->set_next(get_headcir());

}

}

void CCirList :: InsertCirToEnd(CElem *elem0)

{

if (NullCirList()) InsToNullCir(elem0);

else

{

GoLastCir();

curcir->set_next(elem0);

GoNextCir();

curcir->set_next(get_headcir());

}

}

void CCirList :: PrintCirList()

{

GoBOLCir();

if (NullCirList()) cout<<"List is empty";

else

{

cout<<get_curcir()->get_val()<<" ";

GoNextCir();

while (get_curcir()!=get_headcir())

{

cout<<get_curcir()->get_val()<<" ";

GoNextCir();

}

}//else

}

Соседние файлы в папке Лабораторная работа 1