Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 3 / LIST
.CPP#include<list.h>
list::list(){
lhead=NULL;
lcur=NULL;
id=1;
}
list::list(int &idl){
lhead=NULL;
lcur=NULL;
idl++;
id=idl;
cout<<"List "<<id<<" was created. Head=NULL"<<endl;
}
inline elem* list::GetHead()
{return lhead;}
inline elem* list::GetCur(){
return lcur;}
void list::SetHead(elem *H){
lhead=H;
}
inline int list::isend(){
return lcur->GetNext()!=NULL;
}
inline ColorRound list::GFC(){
return lcur->getO();
}
inline void list::SetCur(elem *C){
lcur=C;}
inline void list::gohead()
{
lcur=lhead;
}
void list::gonext(){
if (lcur->GetNext()==NULL)
{
cout<<"End of the list!";
return;}//if
lcur=lcur->GetNext();
}
list::~list(){
if (lhead==NULL) return;
elem *p;
gohead();
while (isend()){
p=GetCur();
gonext();
delete p;}
delete GetCur();
cout<<"List "<<id<<" was destroyed"<<endl;
}
void list::move(double x0,double y0, int num){
gohead();
int i;
for (i=1;i<num;i++)
{
if (!isend())
{
cout<<"Error number of list! Element isn't found!"<<endl;
return;
}
gonext();
}
GFC().Move(x0,y0);
}//move
void list::insert(ColorRound f){
elem *MJ= new elem(f,NULL);
gohead();
if (lhead==NULL)
{
SetHead(MJ);
return;
}
while (isend())
{gonext();}
GetCur()->SetNext(MJ);
}//insert
/*
int list::invar(){
if ( (int(GetHead() )) ^ (int(GetEnd()) ) ^ (int(GetCur()) ) )
return 0;
gohead();
float tsq=GetCur()->GetF().square();
while (!isend()) {
gonext();
/*if (tsq->GetCur()->GetF.square())
return 0; */ /*
tsq=GetCur()->GetF().square();
}//while
return 1;
}//invar
*/
void list::del(int num){
int i;
gohead();
if (GetHead()==NULL) {
cout<<"List is empty";
return;}//if
for (i=1;i<num-1;i++)
if (isend()){ gonext();}
else
{
cout<<"Element isn't found";
getch();
return;
}
elem *p;
p=GetCur();
if (num==1){
SetHead(p->GetNext());
delete p;
gohead();
cout<<"Element number "<<num<<" was deleted from list"<<endl;
return;
}//if
if (!isend())
{cout<<"Element isn't found";
getch();
return;
}//if
if (GetCur()->GetNext()->GetNext()==NULL)
{
GetCur()->SetNext(NULL);
cout<<"Element number "<<num<<" was deleted from list"<<endl;
delete p->GetNext();
return;
}//if
GetCur()->SetNext(p->GetNext()->GetNext());
//delete p->GetNext();
gohead();
}//del
void list::print(){
gohead();
if (GetHead()==NULL){
cout<<"List is empty";
return;
}//if
while (isend())
{
GFC().printing();
cout<<"Square="<<GFC().square()<<endl<<endl;
gonext();
}//while
GFC().printing();
cout<<"Square="<<GFC().square()<<endl<<endl;
}//print
Соседние файлы в папке Лабораторная работа 3