Codice: Seleziona tutto
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
struct entry {
char stringa;
struct entry *next;
};
char* inserisci_nodo(char*puntatoreprec, char *puntatoresucc){
struct entry *puntatore;
puntatore=(struct entry*)malloc(sizeof(struct entry));
puntatoreprec->next=puntatore;
puntatore->next=puntatoresucc;
printf("inserisci la stringa");
scanf("%s",puntatore->stringa);
}
int main () {
char a,b,c;
int x;
struct entry n1,n2,n3;
struct entry *start=&n1;
printf("inserisci le tre stringhe");
scanf("%s%s%s",&a,&b,&c);
n1.stringa=a;
n1.next=&n2;
n2.stringa=b;
n2.next=&n2;
n3.stringa=b;
n3.next=NULL;
printf("dove vuoi inserire il nuovo nodo?\npremere 0 se lo si vuole in testa;\n altrimenti premere il numero corrispondente al nodo precedente; ");
scanf("%d",&x);
switch(x) {
case(0): {
struct entry *puntatore_nuovo;
puntatore_nuovo=(struct entry*)malloc(sizeof(struct entry));
printf("inserire una nuova stringa");
scanf("%s",&puntatore_nuovo->stringa);
while(puntatore_nuovo!=NULL)
printf("%s\n",puntatore_nuovo->stringa);
puntatore_nuovo=puntatore_nuovo->next;
break;
}
case(1): {
inserisci_nodo(&n1,&n2);
while(start!=NULL){
printf("%s",start->stringa);
start=start->next;
}
break;
}
case(2):{
inserisci_nodo(&n2,&n3);
while(start!=NULL){
printf("%s",start->stringa);
start=start->next;
}
break;
}
case(3): {
struct entry *end=NULL;
inserisci_nodo(&n3,end);
while (start!=NULL){
printf("%s",start->stringa);
start=start->next;
}
break;
}
}
return 0;
}
