• Lunes 29 de Abril de 2024, 05:11

Autor Tema:  Problemita!! Faul: access violation  (Leído 1896 veces)

borca

  • Miembro activo
  • **
  • Mensajes: 60
    • Ver Perfil
Problemita!! Faul: access violation
« en: Domingo 17 de Febrero de 2002, 21:38 »
0
bueno estoy trabajando con funciones templates, implemetandolo en una lista..al momento de la compilacion me aparece Fault: access violation...Quien me podria decir cual es el [ERROR]
Gracias;)

#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <stdlib.h>

template <class U>
class Liste {
  class Elem {
    friend class Liste<U>;
    U info;
    Elem *next;
    Elem (): info(0), next(NULL) {}
    Elem (U i, Elem *p): info(i), next(p) {}
  };
  Elem *head;
  void Eliminer();  //fonct qui elimine tous les èlèm de las liste
public:
  U Ins(U i);      //insére en tête
  U Tete();        //retourne l'information pointée par tête
  bool Vide () const ;      // Vide
  void Print () const;      // Print
  Liste Suite();                // Suite
  Liste(): head(NULL) {};   //Constr
  Liste& operator= (const Liste&); //operator
  Liste (const Liste&);  //copy constr
  ~Liste ();              //Destr
 };


//-----------------------------------------------------------------

template <class U>
void Liste<U>::Eliminer() {

  Elem* q;
   for (Elem* p = head; p!=NULL; p = q)
      { q = p->next; delete p; }
}

//--------------------------------------------------------------
template <class U>        //insere l'èlèment en tête
U Liste<U>::Ins(U i){
{
 head = new Elem(i, head);
} return (head->info); }

template <class U>       //retourne l'information pointée par la tête
U Liste<U>::Tete() {
return head->info;
}

template <class U>     //élimine ce qui est pointée par tête
Liste Liste<U>::Suite() {  //et tête passe un élément après
  if (!Vide()) {
   Elem* p=head;
   head=head->next;
   p->next=NULL;
   delete p;
 } return *this;

}

template <class U>           //imprime l'information de chaque élém de la liste
void Liste<U>::Print() const {
 for(Elem *f=head; f!=NULL; f=f->next)
 cout << f->info << setw(3);
}

template <class U>       //teste si la tête ne pas vide
bool Liste<U>::Vide() const{

return !head ;
}


//-----------------------------------------------------------------

template <class U>           //assigne à une nouvelles liste la liste courrante
Liste<U>& Liste<U>::operator= (const Liste& S) {
   if (this!= &S) { Eliminer();
   Elem** q = &head;
   for( Elem *p= S.head; p!=NULL; p=p->next)
     { *q= new Elem(p->info, *q); q = & (*q)->next; }
 }  return * this;
}

template <class U>           //copy constr
Liste<U>::Liste (const Liste& S) {
 Elem** q = &head;
 for (Elem* p=S.head; p; p=p->next)
    {  *q = new Elem (p->info, head); q = & (*q)->next; }
}

template <class U>          //le destr apelle la fonct Eliminer
Liste<U>::~Liste() {
Eliminer(); }
//-------------------------------------------------------------



/*main () {
  {
    clrscr();
   Liste<char> L1;

   cout << L1.Vide() << endl;
   L1.Ins('A'); L1.Ins('L'); L1.Ins('V');
   cout << "Print for L1" << endl;
   cout << L1.Tete() << endl;
   L1.Print();
   L1.Suite();
   cout << endl << L1.Vide() << endl;
   L1.Print();
   //Liste<char> L2;
   //L2=L1;
//   cout << "Print for L2 " << L2.Vide() << endl;
   //L2.Suite();
   //L2.Print() ; cout << endl << L2.Vide() << endl;
  } return EXIT_SUCCESS;
}
  */

  main () {
  {
    clrscr();
   Liste<int> L1;
   L1.Ins(6); L1.Ins(3); L1.Ins(5); L1.Ins(1);
   cout << "Print for L1" << endl << L1.Tete() << endl;
   L1.Print();
   L1.Suite();
   cout << endl << L1.Vide() << endl;
   L1.Print();
    Liste<int> L2;
   L2=L1;
   L2.Ins(13);
   cout << endl << "Print fot L2" << endl << L2.Vide() << endl;
   L2.Print() ; cout << endl << L2.Vide() << endl;

  }  return EXIT_SUCCESS;