Skip to content

Instantly share code, notes, and snippets.

@enlacee
Created March 20, 2018 03:15
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 enlacee/64ffc7695b8e918745852d961013f94f to your computer and use it in GitHub Desktop.
Save enlacee/64ffc7695b8e918745852d961013f94f to your computer and use it in GitHub Desktop.
02.text
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