Скачиваний:
33
Добавлен:
01.05.2014
Размер:
3.7 Кб
Скачать
//” ©«: SrvList.cpp
//Љ« бб "‘ЇЁб®Є Є«ЁҐ­в®ў ­  бҐаўҐаҐ". ђҐ «Ё§ жЁп.
//Ђўв®а: ‘ҐаЈҐҐў Њ.‚. Ја.3352
//„ в : 21.05.06, ђҐ¤ ЄжЁп: 1.0


#include<iostream.h>
#include<conio.h>
#include "SrvList.h"
//#include "SrvElem.cpp"
using namespace std;     


#ifndef __SrvList_CPP
#define __SrvList_CPP


////////////////////////////////////////////////////////////////
/*
  Constructor
*/
CSrvList::CSrvList():first(NULL)
{
 cout <<"\n>CSrvList";
};
////////////////////////////////////////////////////////////////
/*
  Destructor
*/
CSrvList::~CSrvList()
{
 this->clear();
 cout <<"\n>~CSrvList";
};
////////////////////////////////////////////////////////////////
/*
  Check if the  list is empty (1-empty, 0-not empty)
*/
int CSrvList::isEmpty(void) const
{
 return (first == NULL)? 1 : 0;
};
////////////////////////////////////////////////////////////////
/*
  Insert item into the list  with value of problem part val
*/
void CSrvList::insertItem(CClient*n)
{
//adding value to the list
CSrvItem* newItem = new CSrvItem(n,NULL);

if(first == NULL){
   first = newItem;
}else{
   CSrvItem* tmp = first;
   while(tmp->getNext() != NULL){tmp = tmp->getNext();}
   tmp->setNext(newItem);
}
};
////////////////////////////////////////////////////////////////
/*
  Clearing all the list
*/
void CSrvList::clear()
{
if(first == NULL)
{
 cout <<"\nCSrvList: ‘ЇЁб®Є Є«ЁҐ­в®ў ®зЁйҐ­";
 return;
};

if(first->getNext() == NULL)
   {
   delete first;
   first=NULL;
   cout <<"\nCSrvList: ‘ЇЁб®Є Є«ЁҐ­в®ў ®зЁйҐ­";
   return;
   }

CSrvItem *tmp,
         *t;

tmp=first;
t=first->getNext();

while(t->getNext()!=NULL)
     {
     delete tmp;
     tmp=t;
     t=t->getNext();
     }

delete tmp;
delete t;

first=NULL;

cout <<"\nCSrvList: ‘ЇЁб®Є Є«ЁҐ­в®ў ®зЁйҐ­";
};
////////////////////////////////////////////////////////////////
/*
  Show List on the screen
*/
void CSrvList::show()  const
{
cout<<"\n>>>\n";

if(first == NULL){cout<<" ‡ аҐЈЁбваЁа®ў ­­ле Є«ЁҐ­в®ў ­Ґв.\n<<<\n";return;}

int number = 0;

CSrvItem *tmpPtr;//temporary pointer to move throught the list

tmpPtr = first;    //starting from the begining

//moving till the end
while(tmpPtr->getNext() != NULL)
     {
     //printing the inf of the item and move forward
     tmpPtr->getPoint()->show();
     cout<<"\n";
     tmpPtr=tmpPtr->getNext();
     number++;
      }
tmpPtr->getPoint()->show();
number++;
cout <<"\n‚ᥣ®:"<<number<<"\n<<<\n";
};
////////////////////////////////////////////////////////////////
/*
  return pointer to the first element
*/
CSrvItem* CSrvList::getFirstPtr()
{
  return first;
};
////////////////////////////////////////////////////////////////
/*
  get registered client with ID= id
*/
CClient* CSrvList::getClientByID(int id)
{
if(first == NULL){
   return NULL;
}else{
   CSrvItem* tmp = first;
   if(tmp->getPoint()->getID() == id)return tmp->getPoint();
   while(tmp->getNext() != NULL){
   tmp = tmp->getNext();
   if(tmp->getPoint()->getID() == id)return tmp->getPoint();
   }
//   tmp->setNext(newItem);
   if(tmp->getPoint()->getID() == id)return tmp->getPoint();
   
}
return NULL;
}
////////////////////////////////////////////////////////////////
/*
  walk by all  -  iterator
*/
    int CSrvList::hasNextClient()
    {
     if(cur == NULL)return 0;
     cur = cur->getNext();
     if(cur == NULL)return 0;
     return 1;
    }

    CClient* CSrvList::getCurClient()
    {
     if(cur == NULL) return NULL;
     return cur->getPoint();
    }

    void CSrvList::resetNextClient()
    {
     cur = first;
    }

#endif
Соседние файлы в папке Kurs