codice:
#include <stdio.h>
#include <stdlib.h>
#define MAXNUM 3
typedef struct CELLA *LISTA;
typedef struct BIN{
int chiave;
char valore;
}BIN;
typedef struct CELLA{
BIN info;
LISTA* next;
}CELLA;
void in_coda(BIN bin, LISTA* l);
void mk_bintab(BIN* input, LISTA *tab);
LISTA testa(LISTA* l);
void print(LISTA *l);
int main(){
LISTA array[MAXNUM]={NULL};
BIN input[8];
input[0].chiave=2;
input[0].valore='A';
input[1].chiave=1;
input[1].valore='B';
input[2].chiave=1;
input[2].valore='C';
input[3].chiave=3;
input[3].valore='D';
input[4].chiave=2;
input[4].valore='E';
input[5].chiave=1;
input[5].valore='F';
input[6].chiave=3;
input[6].valore='G';
input[7].chiave=2;
input[7].valore='H';
mk_bintab(input, array);
//printf("%d\n", (LISTA)testa((LISTA*)array[1])->info.chiave);
/*LISTA a=calloc(1, sizeof(struct CELL));
a= testa(array[0]);
printf("%d", a->info.chiave);*/
print(array);
}
LISTA testa(LISTA* l){
LISTA aux= calloc(1, sizeof(struct CELLA));
if(l!=NULL){
aux=(LISTA)l;
l=(*l)->next;
}
return aux;
}
void mk_bintab(BIN* input, LISTA *tab){
int i;
for(i=0;i<8;i++){
in_coda(input[i], (LISTA*)tab[input[i].chiave-1]);
}
}
void in_coda(BIN bin, LISTA* l){
if(l==NULL){
LISTA aux=calloc(1, sizeof(struct CELLA));
aux->info.chiave=bin.chiave;
aux->info.valore=bin.valore;
aux->next=NULL;
*l=aux;
printf("%p, %p\n", *l, l);
//printf("%d %c\n", (*l)->info.chiave, aux->info.valore);
}
else{
printf("l non nulla...\n");
in_coda(bin, (*l)->next);
}
}
void print(LISTA *l){
int i;
for(i=0;i<MAXNUM;i++){
if(l[i]==NULL){
printf("NULL\n");
}
else{
printf("%d\n%c\n", l[i]->info.chiave, l[i]->info.valore);
print(l[i]->next);
}
}
}