Skip to content

Instantly share code, notes, and snippets.

@MacoChave
Created June 12, 2016 09:17
Show Gist options
  • Save MacoChave/9c6340da9d19135ed57f7d70c41fcb7b to your computer and use it in GitHub Desktop.
Save MacoChave/9c6340da9d19135ed57f7d70c41fcb7b to your computer and use it in GitHub Desktop.
Listas en c
#include <stdlib.h>
#include <stdio.h>
struct Nodo {
int id;
char nombre;
struct Nodo *sig;
};
void insercionInicio(struct Nodo *lista, struct Nodo *temp) {
if (lista == NULL) {
lista = malloc(sizeof(struct Nodo));
lista -> id = 5;
lista -> nombre = 'a';
lista -> sig = NULL;
} else if (lista -> sig == NULL || lista -> sig != NULL) {
temp = lista;
lista -> id = 6;
lista -> nombre = 'b';
lista -> sig = temp;
temp = NULL;
}
}
int main(void) {
//INICIAR LA LISTA A NULL
struct Nodo *lista = NULL, *actual, *temp;
int id;
char nombre;
/*
* INSERCION AL INICIO
*/
if (lista == NULL) {
lista = malloc(sizeof(struct Nodo));
lista -> id = 5;
lista -> nombre = "alberto";
lista -> sig = NULL;
} else if (lista -> sig == NULL || lista -> sig != NULL) {
temp = lista;
lista -> id = 7;
lista -> nombre = "juan";
lista -> sig = temp;
temp = NULL;
}
while (lista -> sig == NULL) {
printf("id: %d, nombre: %hhd",lista -> id, lista -> nombre);
lista = lista -> sig;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment