Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct nodo{
- char *inf;
- struct nodo *next;
- struct nodo *back;
- };
- typedef struct nodo nodo;
- void stampa(nodo* start)
- {
- int i=1;
- printf("\nSTAMPA DELLA LISTA FULL");
- while(start!=NULL)
- {
- printf("\nelemento: %2d, m: %7p, s->back: %8p, s->inf: %s m->next: %8p",i,start,start->back,start->inf,start->next);
- start=start->next;
- i++;
- }
- }
- void stampa_small(nodo *start)
- {
- int i=1;
- printf("\nSTAMPA DELLA LISTA small");
- while (start!=NULL)
- {
- printf("%s ",start->inf);
- start=start->next;
- i++;
- }
- }
- int contaNode(nodo *start)
- {
- int conta=0;
- while(start!=NULL)
- {
- start=start->next;
- conta++;
- }
- return conta;
- }
- nodo* ricercaPosizione(nodo *start, int pos )
- {
- int i=1;
- while ( i < pos && start != NULL){
- start = start->next;
- i = i+1;
- }
- return start;
- }
- nodo* inserimento(nodo *start, char *v, int j)
- {
- int i=1;
- int s_word;
- s_word=strlen(v);
- printf("stampo v: %s\n", v);
- nodo *app;
- nodo *end;
- app=start;
- end=start;
- if(j==1)//CIOÈ SE IL NODO È UNO
- {
- printf("entro nell'if\n");
- app=start;
- app->back=NULL;
- app->next=NULL;
- app->inf=(char*)malloc(sizeof(char)*s_word);
- app->inf=v;
- return start;
- }
- else{
- app=start;
- printf("entro nell'else\n");
- app=ricercaPosizione(start,contaNode(start));
- end=app;
- app->next=(nodo*)malloc(sizeof(nodo));
- app=app->next;
- app->back=end;
- app->inf=(char*)malloc(sizeof(char)*strlen(v));
- app->inf=v;
- app->next=NULL;
- return start;
- }
- return start;
- }
- int main()
- {
- system("clear");
- int sum,i,s_word=0;
- int conta_p;
- char word[26];
- nodo *master1;
- master1=(nodo*)malloc(sizeof(nodo));
- printf("Quante parole vuoi inserire: ");
- scanf("%d",&conta_p);
- for (i=1;i<=conta_p;i++) //i indica quante parole
- {
- printf("\ninserisci la %da parola: ",i);
- scanf("%s",word);
- master1=inserimento(master1,word,i);
- stampa(master1);
- }
- free(master1);printf("\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement