Witam!
Mam problem z wyswietleniem listy w menu. Gdy dodaje elementy to ta lista mi sie ladnie pokazuje, ale gdy pozniej chce przejsc do pozycji drugiej - czyli wyświetlanie wszystkich elementów listy, to juz jej nie ma. Bardzo prosze o pomoc!
#include <iostream>
using namespace std;
struct tListaItem
{
int dane;
tListaItem *nastepny;
};
void nowy(tListaItem** glowa, int wartosc)
{
if (*glowa == NULL)
{
*glowa = new tListaItem();
(*glowa)->nastepny = NULL;
(*glowa)->dane = wartosc;
}
else {
tListaItem *tmp = *glowa;
tListaItem *nowy = new tListaItem();
nowy->nastepny = NULL;
nowy->dane = wartosc;
while (tmp->nastepny)
{
tmp = tmp->nastepny;
}
tmp->nastepny = nowy;
}
}
void pokaz(tListaItem* glowa)
{
int element =0;
while (glowa)
{
cout << glowa-> dane << endl;
element++;
glowa = glowa->nastepny;
}
cout << "Lista ma " << element << " elementow" << endl;
}
int main()
{
poczatek:
tListaItem *glowa = NULL;
int a ,liczba;
char wybor;
cout << "MENU" << endl;
cout <<"a. dodawanie elementow na koncu listy \nb. wyswietlenia wszystkich elementow listy \nc. usuniecie dowolnego elementu listy \nd. zakoncz program" << endl;
cin >> wybor;
switch(wybor)
{
case 'a':
{
cout << " Ile chcesz dodac elementow? " << endl;
cin >> liczba;
for(int i=0; i<liczba; i++)
{
cout << "Podaj" << i << "element:" << endl;
cin >> a;
nowy(&glowa, a);
pokaz(glowa);
}
break;
}
case 'b':
{
pokaz(glowa);
break;
}
case 'c':
{
}
case 'd':
{
exit(0);
break;
}
}
goto poczatek;
return 0;
}