Robilem wedlug schematu moja liste, dla przykladu w mainie chcialem stworzyc na poczatku liste 2 elementow ale po kompilacji program sie wysypuje, moze uda wamsie znalezc co jest nie tak
#include <iostream>
using namespace std;
class Element{
public:
int wartosc;
Element* nastepny;
Element* poprzedni;
Element();
~Element();
};
Element::Element(){
nastepny=this;
poprzedni=this;
}
Element::~Element(){
if (poprzedni) poprzedni->nastepny=nastepny;
if (nastepny) nastepny->poprzedni=poprzedni;
}
class Lista{
public:
// Lista();
void DodajNaPoczatek(Element*,Element*,int);
void WypiszListe(Element*);
};
void Lista::WypiszListe(Element *head)
{
while (head!=NULL)
{
std::cout<<head->wartosc<<" ";
head=head->nastepny;
}
}
void Lista::DodajNaPoczatek(Element* head, Element* tail,int n_wartosc){
Element *nowy;
nowy= new Element;
nowy->wartosc=n_wartosc;
if (head==NULL && tail==NULL)
{
head=nowy;
tail=nowy;
nowy->nastepny=NULL;
nowy->poprzedni=NULL;
}
else
{
nowy->nastepny=head;
nowy->poprzedni=NULL;
head->poprzedni=nowy;
head=nowy;
}
}
int main()
{ int a=5;
int b=6;
Lista nowa;
Element* head;
Element* tail;
head=NULL;
tail=NULL;
nowa.DodajNaPoczatek(head,tail,a);
nowa.DodajNaPoczatek(head,tail,b);
//nowa.WypiszListe(head);
std::cout<<head->wartosc<<" ";
head=head->nastepny;
std::cout<<head->wartosc<<" ";
return 0;
}