#include <iostream>
using namespace std;
struct Wezel
{
int dana;
Wezel* next;
};
void showList(const Wezel* head)
{
if (! head)
{
cout << "Lista jest pusta" << endl;
return;
}
while (head)
{
cout << head->dana << " ";
head = head->next;
}
cout << endl;
}
void Addlist(Wezel *lista, int liczba)
{
Wezel *wsk, *nowy;
wsk = lista;
while (wsk->next != NULL)
{
wsk = wsk->next;
}
nowy = new Wezel;
nowy->dana = liczba;
nowy->next = NULL;
wsk->next = nowy;
}
Wezel* arrayToList(const int tab[], int size)
{
Wezel *Lista;
Lista->next=NULL;
Lista->dana=tab[0];
for(int i=1;i<size;i++)
Addlist(Lista,tab[i]);
return Lista;
}
int main(void) {
int tab[] = {7,5,2,3,4,8,1,7,2};
int size = sizeof(tab)/sizeof(tab[0]);
Wezel *head = arrayToList(tab, size);
showList(head);
}
Widzi ktoś może, dlaczego wysypuje mi się???