mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-29 20:34:27 +01:00
Minor changes
This commit is contained in:
parent
58b9b599fa
commit
f73c8ff2c2
1 changed files with 5 additions and 3 deletions
|
@ -59,7 +59,7 @@ class CircularList
|
||||||
puts(STDOUT.flush)
|
puts(STDOUT.flush)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_tail
|
def delete_head
|
||||||
return if @head.nil?
|
return if @head.nil?
|
||||||
|
|
||||||
if @head.next != @head
|
if @head.next != @head
|
||||||
|
@ -74,7 +74,9 @@ class CircularList
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_tail
|
def delete_tail
|
||||||
if !@head.nil? && (@head.next != @head)
|
return if @head.nil?
|
||||||
|
|
||||||
|
if @head.next != @head
|
||||||
tempNode = @head
|
tempNode = @head
|
||||||
tempNode = tempNode.next while tempNode.next.next != @head
|
tempNode = tempNode.next while tempNode.next.next != @head
|
||||||
tempNode.next = @head
|
tempNode.next = @head
|
||||||
|
@ -103,5 +105,5 @@ obj.print_list
|
||||||
obj.delete_tail
|
obj.delete_tail
|
||||||
obj.print_list
|
obj.print_list
|
||||||
|
|
||||||
obj.delete_tail
|
obj.delete_head
|
||||||
obj.print_list
|
obj.print_list
|
||||||
|
|
Loading…
Add table
Reference in a new issue