Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 18, 2020 22:24
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/7a12cc71ce5cee3559cbdc6574d5f9ab to your computer and use it in GitHub Desktop.
Save parzibyte/7a12cc71ce5cee3559cbdc6574d5f9ab to your computer and use it in GitHub Desktop.
void agregarLineaALista(char *linea) {
// El que se agregará; reservamos memoria
struct nodo *nuevoNodo = malloc(sizeof(struct nodo));
// Le ponemos el dato
strcpy(nuevoNodo->linea, linea);
// Si es el primer elemento que se agrega...
if (superior == NULL) {
superior = nuevoNodo;
return;
}
// Si no, buscamos el último elemento y le asignamos el valor al mismo
struct nodo *temporal = superior;
while (temporal->siguiente != NULL) {
temporal = temporal->siguiente;
}
temporal->siguiente = nuevoNodo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment