PHP Code:
/***
* _ _
* (_) (_)
* __ ____ _ _ _____ ___ ___ ___ ___ _ __ ___
* \ \/ / _` | |/ _ \ \ / / |/ _ \ / __/ _ \| '_ ` _ \
* > < (_| | | (_) \ V /| | (_) | (_| (_) | | | | | |
* /_/\_\__, |_|\___/ \_/ |_|\___(_)___\___/|_| |_| |_|
* __/ |
* |___/
*/
#include <st***.h>
#include <stdlib.h>
#include <string.h>
typedef struct lista {
int *indirizzo;
struct lista * prossimo;
} lista_struct;
//////////////////////////////////////////// prototypes
lista_struct *new_node ( int * address);
lista_struct * add_node(lista_struct * nodo ,lista_struct * lista);
void allprefixsums ( int * a, int n);
int main (void){
int i;
int vet[10]={2,5,1,3,2,6,0,4};
lista_struct *list;
lista_struct *temp_node;
//////////////////////////
list= NULL;
for (i=0;i<8;i++){
printf ("%d ", *(vet +i));
}
printf ("\n");
allprefixsums ( vet, 8);
for (i=0;i<8;i++){
printf ("%d ", *(vet +i));
}
printf ("\n");
for (i=0;i<8;i++){
temp_node = new_node (vet +i);
list = add_node(temp_node,list);
}
for(temp_node = list;temp_node != NULL; temp_node = temp_node->prossimo){
printf("Indirizzo nodo %p\n",temp_node->indirizzo);
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////functions
void allprefixsums ( int * a, int n){
int i;
for (i=1;i<8;i++){
*(a+i)= *(a+i)+ (*(a+i-1));
}
}
lista_struct *new_node ( int * address){
lista_struct * node;
node = (lista_struct *) malloc (sizeof(lista_struct));
node->indirizzo = address;
node->prossimo = NULL;
}
lista_struct * add_node(lista_struct * nodo ,lista_struct * lista){
if ( lista == NULL){
return nodo;
}
lista->prossimo = add_node(nodo,lista->prossimo);
return lista;
}