-
-
Save parzibyte/9b2948535abd18ee8cc010ca70b4afd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAXIMA_LONGITUD_CADENA 1000 | |
struct NodoDeLista | |
{ | |
char nombre[MAXIMA_LONGITUD_CADENA]; | |
// Aquí podrían ir más datos... | |
struct NodoDeLista *siguiente; | |
}; | |
void agregarNodoALista(struct NodoDeLista **nodo, char *nombre) | |
{ | |
struct NodoDeLista *nuevoNodo = malloc(sizeof(struct NodoDeLista)); | |
strcpy(nuevoNodo->nombre, nombre); | |
nuevoNodo->siguiente = NULL; | |
if ((*nodo) == NULL) | |
{ | |
*nodo = nuevoNodo; | |
} | |
else | |
{ | |
agregarNodoALista(&(*nodo)->siguiente, nombre); | |
} | |
} | |
void imprimirLista(struct NodoDeLista *nodo) | |
{ | |
while (nodo != NULL) | |
{ | |
printf("Encontramos un nombre en la lista: '%s'\n", nodo->nombre); | |
nodo = nodo->siguiente; | |
} | |
} | |
int main() | |
{ | |
// https://parzibyte.me/blog | |
struct NodoDeLista *apuntadorLista = NULL; | |
agregarNodoALista(&apuntadorLista, "Luis"); | |
agregarNodoALista(&apuntadorLista, "Parzibyte"); | |
agregarNodoALista(&apuntadorLista, "Link"); | |
agregarNodoALista(&apuntadorLista, "Shovel Knight"); | |
imprimirLista(apuntadorLista); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment