#include <stdio.h>
#include <stdlib.h>
#define popuIni 10
typedef struct _Elem
{
int id;
int pp;
int size[4];
struct _Elem* next;
}Elem;
Elem* elem_new(int id,int pp, int sz0,int sz1,int sz2,int sz3)
{
Elem* e = malloc(sizeof(Elem));
e->id = id;
e->pp = pp;
e->size[0] = sz0;
e->size[1] = sz1;
e->size[2] = sz2;
e->size[3] = sz3;
return e;
}
Elem* create_population()
{
Elem* e;
Elem* first = NULL;
int i;
for ( i = 0; i < popuIni; i++)
{
e = elem_new(i,rand() % 2,rand() % 2,rand() % 2,rand() % 10+1,rand() % 10+1);
e->next = first;
first = e;
}
for (e = first ; e != NULL ; e = e->next)
{
if (e->pp==1)
printf("%d %d %d \n",e->id,e->pp, e->size[0]);
}
return first;
}
int main(void){
create_population();
return (0);
}
usala come traccia nel cercare di tenere un codice comprensibile.