Czy to jest poprawna funkcja do tworzenie listy jednokierunkowej?
nie trzeba bawić się we wskaźniki?
#include <stdio.h>
#include <stdlib.h>
struct element {
int dane;
struct element* nast;
};
typedef struct element ELEMENT;
typedef ELEMENT* ADRES;
ADRES tworz(int tab[])
{
ADRES pocz = NULL, ost = NULL, pom;
int i;
for (i = 0; i < 5; i++) {
pom = (ADRES)malloc(sizeof(ELEMENT));
pom->dane = tab[i];
if (pocz == NULL) {
pocz = pom;
ost = pom;
}
else {
ost->nast = pom;
ost = pom;
}
}
ost->nast = NULL;
return pocz;
}