Umbi_Vox
30-06-2011, 15:18
Ciao a tutti. Ho scritto un programma per un compito, ma sto avendo qualche difficoltà. Il programma che ho scritto è il seguente:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 15
typedef char* string;
typedef struct elem* lista;
struct elem{
string str;
lista next;
};
lista crea_elem(char* str){
lista l= (lista)malloc(sizeof(struct elem));
l->str=(char*)malloc(N* sizeof(char));
strcpy(l->str, str);
l->next=NULL;
return l;
}
void visualizza(lista L){
if(L){
printf("%s\t", L->str);
int length= strlen(L->str);
printf("%d;\t",length);
visualizza(L->next);
}
else
printf("\n");
}
lista insert_ord(lista L, char* s){
if(!L)
return crea_elem(s);
else{
if(strcmp(L->str, s)<0)
L->next= insert_ord(L->next, s);
else{
lista tmp= L;
L= crea_elem(s);
L->next=tmp;
}
return L;
}
}
ma vorrei scrivere la funzione "insert_ord" in modo che sia void... potreste aiutarmi? grazie mille
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 15
typedef char* string;
typedef struct elem* lista;
struct elem{
string str;
lista next;
};
lista crea_elem(char* str){
lista l= (lista)malloc(sizeof(struct elem));
l->str=(char*)malloc(N* sizeof(char));
strcpy(l->str, str);
l->next=NULL;
return l;
}
void visualizza(lista L){
if(L){
printf("%s\t", L->str);
int length= strlen(L->str);
printf("%d;\t",length);
visualizza(L->next);
}
else
printf("\n");
}
lista insert_ord(lista L, char* s){
if(!L)
return crea_elem(s);
else{
if(strcmp(L->str, s)<0)
L->next= insert_ord(L->next, s);
else{
lista tmp= L;
L= crea_elem(s);
L->next=tmp;
}
return L;
}
}
ma vorrei scrivere la funzione "insert_ord" in modo che sia void... potreste aiutarmi? grazie mille