Created
March 20, 2018 03:15
-
-
Save enlacee/64ffc7695b8e918745852d961013f94f to your computer and use it in GitHub Desktop.
02.text
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
def insertarAlInicio(nuevoValor) | |
nuevoNodo = [nuevoValor, nil] # crear un nodo nuevo | |
# crear NODO | |
if @inicio == nil | |
@inicio = nuevoNodo | |
else | |
nuevoNodo[1] = @inicio | |
@inicio = nuevoNodo | |
end | |
end | |
def insertarAlFinal(valor) | |
nuevoNodo = [] | |
nuevoNodo = [valor, nil] | |
if @inicio == nil | |
@inicio = nuevoNodo | |
else | |
p = @inicio | |
while p[1] != nil | |
p = p[1] | |
end | |
p[1] = nuevoNodo | |
end | |
end | |
# 01 | |
def generarNodo(n) | |
@inicio = nil | |
nuevoValor = 0 | |
for i in 0...n | |
#puts i | |
nuevoValor = nuevoValor + 100 | |
insertarAlInicio(nuevoValor) | |
#insertarAlFinal(nuevoValor) | |
end | |
end | |
# 02 | |
def agregarNodo(valor, posicion) | |
nuevoNodo = [] | |
nuevoNodo = [valor, nil] | |
if @inicio == nil | |
#@inicio = nuevoNodo | |
else | |
p = @inicio | |
while p[1] != nil | |
p = p[1] | |
end | |
p[1] = nuevoNodo | |
end | |
end | |
### init | |
generarNodo(6) | |
print @inicio | |
### agregar un nodo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment