Untitled
unknown
c_cpp
a year ago
957 B
8
Indexable
// Online C compiler to run C program online
#include <stdio.h>
nodo_t* media_lista(nodo_t *head) {
if (head == NULL) {
return NULL;
}
// Calcola la lunghezza della lista
int lunghezza = 0;
nodo_t *corrente = head;
while (corrente != NULL) {
lunghezza++;
corrente = corrente->next;
}
node_t* risultato= NULL;
int i, j;
for(i=0; i<(lunghezza +1)/2; i++) //lunghezza = 7
{
nodo_t *nodo1 = head;
for(j=0; j<i; j++)
{
nodo1 = nodo1->next;
}
nodo_t *nodo2 = head;
for(j=0; j<lunghezza-i-1; j++)
{
nodo2 = nodo2->next;
}
int media = (nodo1->n + nodo2->n) / 2;
risultato = inserisciCoda(risultato, media);
}
return risultato;
}
int main() {
// Write C code here
printf("Try programiz.pro");
return 0;
}Editor is loading...
Leave a Comment