Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/cola.c Secret

Created April 15, 2022 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/9b2948535abd18ee8cc010ca70b4afd2 to your computer and use it in GitHub Desktop.
Save parzibyte/9b2948535abd18ee8cc010ca70b4afd2 to your computer and use it in GitHub Desktop.
#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