Lista vinculada de inicialización de matriz,
#include
#include
typedef estructura _NODE
{
int datos;
estructura _NODE* siguiente;
}NODE
int TEST_ARRAY[] = {1,2,3,4,5 ,6,7,8,9,10};
struct _NODE * __gListTest = NULL;
int ListInit(struct _NODE *list, int *pNum, int num);
int main()
{
NODO *list_ptr = NULL;
NODO *next_ptr = NULL;
int i = 0;
__gListTest = (NODE *)calloc(1,sizeof(NODE));
if(__gListTest == NULL)
{
printf("calloc error\n");
return -1;
}
if(ListInit(__gListTest, TEST_ARRAY, tamaño de (TEST_ARRAY)/tamaño de (int)) == -1)
{
printf("error de inicio\n");
retorno -1;
}
//La memoria solicitada dinámicamente debe liberarse manualmente
list_ptr = __gListTest;
for(i=0 ; i { printf("número de lista %d:data:%d, siguiente:0x%x\n ",i+1,list_ptr->datos,list_ptr->siguiente); next_ptr = list_ptr->siguiente; list_ptr->datos = 0; list_ptr->siguiente = NULL; free(list_ptr); list_ptr = next_ptr; } printf(" ¡printf cualquier clave para detener el programa!"); getchar(); return 0; } int ListInit( struct _NODE *list, int *pNum, int num) { // NODE *list_ptr = lista; NODE *next_ptr = NULL; int i = 0; for(i=0; i { next_ptr = (NODO *)calloc(1,tamañode(NODO)); if(next_ptr == NULL) { printf("callo c error\n"); return -1; } list_ptr->data = pNum[i]; list_ptr->siguiente = next_ptr; list_ptr=list_ptr->siguiente; } return 0;// }