|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: Sep 2009
Messaggi: 1
|
Problemi con liste in C
Salve a tutti,sono nuovo di questo forum...Avrei un paio di problemi che non riesco a venirne a capo se ce qualcuno che mi può aiutare la ringrazio in anticipo...
problema 1 Data una lista ed un intero definire una funzione iterativa in C che restituisce in output il numero max di occorrenze... typedef struct nod { int data; struct nod * next; }node; node *newnode(void) { return(node*)malloc(sizeof(node)); } int occ (node *l,int n) { int MAX = 0; int count = 0; if(l == NULL) return MAX; while(l != NULL) { if(l->data == n && count <= MAX){ count++; l = l->next;} else if(count > MAX) MAX = count; count = 0; l = l->next; }return MAX; } ma non riesco a farla funzionare... problema 2 Data una lista L ed un intero n definire una funzione iterativa che da in output una copia dei nodi di L in posizione maggiore di n... node * copymax (node *l,int n) { int pos = 1; node *p;*head,*tail; head = NULL; if(l == NULL) return NULL; while (l!=NULL) { if(pos > n) { p = newnode(); p->data = l->data; p->next = NULL; if(head == NULL){head = p; tail = p;} else {tail->next = p; tail = tail->next;} } pos++; l = l->next; } return p; } Probema 3 ed ultimo... data una lista L e due interi x e y definire una funzione iterativa che da in output una nuova lista cotenente i nodi in posizione multipla di y che contengono un intero maggiore di x node * duplmult(node * l,int x,int y) { node *p, * head, *tail; int pos = 1; head = NULL; if(l == NULL) return NULL; while(l != NULL) { if((pos % y == 0) && (l->data >x)) { p = newnode(); p->data = l->data; p->next = NULL; if(head == NULL){head = p; tail = p;} else {tail->next = p; tail = tail->next;} } else pos++; l = l->next; }return p; } Grazie |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 13:53.



















