						/******************************/
						/*******  CLASS LISTE  ********/
						/******************************/

#include <stdlib.h>
#include <assert.h>
#include "liste.h"


void Liste::Insertion( int xx, int yy,int l, char *co, float ni )
{
  char *m=new char[l]; int i;
  Contour *pt = new Contour( xx, yy, l, m, ni, liste );
  assert( pt != 0 );
  if ( liste == 0 ) { liste=pt; }
  else {  fin_liste->succ=pt; }

  for(i=0;i<l;i++){ m[i]=co[i]; }
  fin_liste=pt;
}
int Liste::Dimension()
{
  int dim=1;
  Contour *pt = liste;
  if( liste==0 )                 { return (0); }
  else if( liste->succ == 0 )         { return (1); }
  else if ( liste->succ==fin_liste )  { return (2); }
  else
	 {
		do{pt=pt->succ; dim++;} while(pt!=fin_liste);
	 }
  return(dim); }

void Liste::El1()
{
  Contour *pt =  liste;
  Contour *tmp = pt; delete[] tmp->code;
  pt=pt->succ;
  delete tmp;
  liste=pt;
}
void Liste::Change( int xx, int yy,int l, char *co, float ni )
{

  char *m=new char[l]; int i;
  Contour *pt = new Contour( xx, yy, l, m, ni, liste );
  assert( pt != 0 );
  if ( liste == 0 ) { liste=pt; }
  else { Contour *tmp = liste; liste=pt; delete[] tmp->code; delete tmp;}

  for(i=0;i<l;i++){ m[i]=co[i]; }
  fin_liste=pt;
}

void Liste::Elimination()
{
  Contour *pt = liste;
  while ( pt )
  {
	 Contour *tmp = pt; delete[] tmp->code;
	 pt = pt->succ;
	 delete tmp;
  }
  liste = fin_liste = 0;
}

char* Liste::Lire(int*cx,int*cy,int*ct,float*cn)
{
  Contour *pt=liste;
  *cx=pt->x; *cy=pt->y; *ct=pt->lon; *cn=pt->niveau;
  return(pt->code);
}
int Liste::Lire_x(int pas)
{ int i; Contour *pt=liste;
  if(pas==0) { return pt->x; }
  else { for(i=0;i<pas;i++) { pt=pt->succ; } return pt->x; }
}
int Liste::Lire_y(int pas)
{ int i; Contour *pt=liste;
  if(pas==0) { return pt->y; }
  else { for(i=0;i<pas;i++) { pt=pt->succ; } return pt->y; }
}
int Liste::Lire_lon(int pas)
{ int i; Contour *pt=liste;
  if(pas==0) { return pt->lon; }
  else { for(i=0;i<pas;i++) { pt=pt->succ; } return pt->lon; }
}
char* Liste::Lire_vett(int pas)
{ int i; Contour *pt=liste;
  if(pas==0) { return pt->code; }
  else { for(i=0;i<pas;i++) { pt=pt->succ; } return pt->code; }
}

float Liste::Lire_niv(int pas)
{
  int i;
  Contour *pt=liste;
  if(pas==0) { pt=liste; }
  else{ for (i=0;i<pas;i++)
		  { pt=pt->succ; }
		}
  return (pt->niveau);
}



