Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 6, 2019 02:49
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/87bbc105c784437aee1085a933c177e5 to your computer and use it in GitHub Desktop.
Save parzibyte/87bbc105c784437aee1085a933c177e5 to your computer and use it in GitHub Desktop.
void insertar(struct Nodo *nodo, int dato) {
// ¿Izquierda o derecha?
// Si es mayor va a la derecha
if (dato > nodo->dato) {
// Tienes espacio a la derecha?
if (nodo->derecha == NULL) {
nodo->derecha = nuevoNodo(dato);
} else {
// Si la derecha ya está ocupada, recursividad ;)
insertar(nodo->derecha, dato);
}
} else {
// Si no, a la izquierda
if (nodo->izquierda == NULL) {
nodo->izquierda = nuevoNodo(dato);
} else {
// Si la izquierda ya está ocupada, recursividad ;)
insertar(nodo->izquierda, dato);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment