Скачиваний:
13
Добавлен:
01.05.2014
Размер:
3.97 Кб
Скачать
//File clist.cpp
//Naznachenie: Opredelenie funkcij klassa "spisok elementov"
//Author: Pavel Morozov
//Redakcija: 1.0 10.02.07

#ifndef clist_cpp
#define clist_cpp

#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>

#include"clist.h"
#include"celement.h"
#include"celement.cpp"

//--------------------Konstruktor--------------------------
CList::CList()
       {

	
	     cprintf("\nKonstruktor CList sozdaet pustoj spisok");
	     cout<<endl<<endl;

	     Lptr=NULL;
          

       }

//--------------Funkcii interfeisa-----------------------



void CList::Insert(CElement *Eptr)
//Vkliuchenie elementa v spisok

	{

//	 float x0,x;

	 CElement *TEptr(Lptr);


	 if (!TEptr)   //Spisok pust
     {
       Lptr=Eptr;


       cout<<endl<<endl;
       cprintf("Vstavka v pustoj spisok");
       cout<<endl<<endl;
     }

	   else
	   {
   

	      while (TEptr->GetNext()) //Poisk mesta v spiske
		  {
			   TEptr=TEptr->GetNext();
             
		  }

	      if(!(TEptr->GetNext()))  //Vstavim v konec spiska
	      {
           

                cout<<endl<<endl;
		cprintf("Vstavka v konec spiska");
                cout<<endl<<endl;
	        TEptr->SetNext(Eptr); 
         

	      }

	 
	     }

     
}


void CList::Divide(  CList &LR1, CList &LR2)
//Razdelenie spiska na 2 spiska LR! i LR2
	{  
	  CElement *TEptr=Lptr;  //Ukazatel ishodnogo spiska
	  float Fptr;              //Znachenie tekushego elementa
      int l=0;int m=0;

	  while (TEptr)   //
	  {
	     Fptr=TEptr->GetFptr();//->GetX(x0);

	     if (Fptr>0)                  //Znachenie tekushego elementa bolshe 0
	     {
	       LR1.InsToBeg ( TEptr ) ;  //Vkliuchenie tekushego elementa v LR1
	       textcolor(14);
	       cout<<endl<<"Vkliuchaem v LR1"<<endl;
	       textcolor(15);
	   l=l+1;
          
	     }

	     if (Fptr<=0)                 //Znachenie tekushego elementa menshe = 0
	     {
	       LR2.InsToBeg ( TEptr ) ;  //Vkliuchenie tekushego elementa v LR2
	       textcolor(14);
	       cout<<endl<<"Vkliuchaem v LR2"<<endl;
	       textcolor(15);
           m=m+1; 
           
	     }

         
	     TEptr=TEptr->GetNext();     //Ustanovka ukazatelia na tekushij element
	  }
       getch();
       cout<<endl<<"1 spisok "<<l<<" elementov";
       LR1.OutList(l);
       cout<<endl<<"2 spisok "<<m<<" elementov";
       LR2.OutList(m);
       cout<<endl;
	  	}

void CList::InsToBeg ( CElement *Eptr )

//Vstavka v nachalo spiska
	{
        CElement *E;
        E= new CElement (*Eptr);


        if (Lptr==NULL) //spisok pust
		{

		  Lptr=E;
                  //Ustanovka ukazatelia na nachalo spiska
		}
	    else             //Esli spisok ne pust
		{

              E->SetNext(Lptr);
              Lptr=E; 
                 //Ustanovka ukazatelia na nachalo spiska

		}


	}



void CList::OutList(int nomer)
	{
	  textcolor(15);


	     //Atributy
	    float Fptr;
	    int i=1;
	    
	  CElement *Elptr(Lptr);
	  //clrscr();
	  if(Lptr){cout<<endl<<endl<<"Vyvod elementov."<<endl;}
	  if (!Lptr){cout<<endl<<"Spisok elementov pustoj"<<endl;}


	  while((Elptr)&&(nomer>=i))
	  {

		
		Fptr=Elptr->GetFptr();
		//Vyvod znachenija elementa
		cout<<"Znachenie elementa N "<<i
		    <<"  ravno "<<Fptr<<endl;
	       //cout<<endl<<"Nazmite probel..."<<endl;
		i=i+1;

	
		Elptr=(Elptr->GetNext());
	      }
	getch();


     }

//-------------------------Destruktor-------------
CList::~CList()
	 {
	   CElement *TEptr;

	   while(Lptr)
	   {
	     TEptr=Lptr;
	     Lptr=Lptr->GetNext();
	     delete TEptr;
	   }

	   cout<<endl;
	   cprintf("~CList razrushaet spisok...");
	   cout<<endl;
	   cprintf("Spisok unichtozen") ;
	   cout<<endl;
	   cprintf("Nazmite probel...");
	   cout<<endl;
	   getch();
	
	   }




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