Hej!
Implementuje listę jednokierunkową z wykorzystaniem klasy, wszystko się kompiluje, ale mimo to program nie działa tzn. w oknie konsoli nic się nie wyświetla, ani nic nie można wpisać. Czy mógłby ktoś zerknąć na kod (program 3-plikowy).
Z góry dziękuję!
Lista.h
#ifndef LISTA_H_
#define LISTA_H_
#include <string>
struct List
{
int how_many;
std::string animal;
struct List *next;
};
typedef struct List Item;
void change_list(Item &it);
class Lista
{
Item *head;
public:
Lista();
void add_elem();
bool is_empty();
void show_list();
void Lista::visit(void(*pf)(Item &it));
~Lista();
};
#endif LISTA_H_
Lista.cpp
#include "Lista.h"
#include <iostream>
Lista::Lista()
{
head->animal = "Orka";
head->next = NULL;
}
void Lista::add_elem()
{
int nex;
std::string temp;
std::cout << "Podaj zwierzatko: " << temp;
nex = (head->how_many) + 1;
List *now = new List;
now->how_many = nex;
now->animal = temp;
now->next = head;
head = now;
}
bool Lista::is_empty()
{
if (head->next == NULL)
return true;
else
return false;
}
void Lista::show_list()
{
List *now = head;
while (now!= NULL)
{
std::cout << now->how_many << ". " << now->animal << std::endl;
now = now->next;
}
}
Lista::~Lista()
{
}
Lista_main.cpp
#include <iostream>
#include "Lista.h"
using namespace std;
void change_list(Item &it);
int main()
{
Lista one;
Item test;
int n;
one.add_elem();
one.show_list();
cout << "Ile elementow chcesz dodac? ";
cin >> n;
for (int i = 0; i < n; i++)
{
one.add_elem();
}
one.show_list();
cout << endl;
//one.visit(change_list);
one.show_list();
return 0;
}