#include <iostream>
#include <cassert>
using namespace std;
class Lista {
private:
int wartosc;
Lista* nastepny;
public:
Lista(int el) {
wartosc = el;
nastepny = NULL;
}
Lista push(int el) {
Lista temp(el);
temp.nastepny = this;
return temp;
}
int get() {
return wartosc;
}
Lista move() {
return *(this->nastepny);
}
};
int main() {
Lista lista(1);
assert(lista.get()==1);
lista = lista.push(2);
assert(lista.get()==2);
lista = lista.move();
assert(lista.get()==1);
cout << "TESTOWANIE: OK";
}
push ma wstawiać element na początek listy
get zwraca pierwszy element listy
move przesuwa się w liście
Siedzę nad tym już parę godzin i nie wiem, czemu to nie działa? Program kończy mi się tą ostatnią asercją. :(