Grazie intanto per l'interessamento, il programma completo è il seguente, in compilazione continua a non dare errori e anche l'esecuzione sembra funzionare...ma al momento della stampa a video niente.
codice:
#include <stdio.h>
#include <malloc.h>
struct elemento {
int valore;
struct elemento *succ;
};
void inserisci_dati(struct elemento *);
void inserisci_ordinatamente(struct elemento *, struct elemento *);
void stampa_lista(struct elemento *);
int main() {
int a = 1;
struct elemento *p0 = NULL;
while(a != 0) {
inserisci_dati(p0);
printf("continuare a inserire? 1 si 0 no");
scanf("%d", &a); }
stampa_lista(p0);
return(0);
}
void inserisci_dati(struct elemento *p0) {
int num;
printf("Inserisci numero intero positivo:\n");
scanf("%d", &num);
while(num < 0) {
printf("Non puoi inserire numero negativo\n");
printf("Inserisci numero intero positivo:\n");
scanf("%d", &num);
}
struct elemento *s = NULL;
s = (struct elemento *)malloc(sizeof(struct elemento));
s->valore = num;
inserisci_ordinatamente(p0, s);
}
void inserisci_ordinatamente(struct elemento *p0, struct elemento *e){
struct elemento *p1, *p2;
if(p0 == NULL) {
p0 = e; p0->succ = NULL;
}
else if ( e->valore < p0->valore) {
p1 = e; p1->succ = p0; p0 = p1;
}
else {
p1 = p0;
while(e->valore > p1->succ->valore && p1->succ != NULL) {
p1 = p1->succ; }
if (p1->succ != NULL) {
p2 = p1->succ;
p1->succ = e;
p1->succ->succ = p2; }
else {
p1->succ = e;
p1 = p1->succ;
p1->succ = NULL;
}
}
}
void stampa_lista(struct elemento *p0) {
while(p0 != NULL) {
printf("Elemento %d\n", p0->valore);
p0 = p0->succ;
}
}