File tree 2 files changed +81
-1
lines changed
2 files changed +81
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
39
39
| [ Fila Encadeada Dinâmica] [ 19 ] | [ C/C++] ( /src/c/FilaEncadeadaDinamica.c ) | Java | Python | Go | Ruby | Javascript | Pascal |
40
40
| [ Grafo] [ 20 ] | [ C/C++] ( /src/c/Grafos.c ) | Java | Python | Go | Ruby | Javascript | Pascal |
41
41
| [ Lista Circular Ligada] [ 52 ] | [ C/C++] ( /src/c/ListaCircularLigada.c ) | Java | [ Python] ( /src/python/lista_encadeada_circular.py ) | Go | Ruby | Javascript | Pascal |
42
- | [ Lista Encadeada] [ 22 ] | C/C++ | Java | [ Python] ( /src/python/lista_encadeada.py ) | Go | Ruby | [ Javascript] ( /src/javascript/ListaSimplesmenteEncadeada.js ) | Pascal |
42
+ | [ Lista Encadeada] [ 22 ] | C/C++ | Java | [ Python] ( /src/python/lista_encadeada.py ) | Go | [ Ruby] ( /src/ruby/Lista_encadeada.rb ) | [ Javascript] ( /src/javascript/ListaSimplesmenteEncadeada.js ) | Pascal |
43
43
| [ Lista Duplamente Encadeada] [ 23 ] | [ C/C++] ( /src/c/ListaDuplamenteEncadeada.c ) | [ Java] ( /src/java/ListaDuplamenteEncadeada.java ) | [ Python] ( /src/python/lista_duplamente_encadeada.py ) | Go | Ruby | [ Javascript] ( /src/javascript/ListaDumplamenteEncadeada.js ) | Pascal |
44
44
| [ Lista Ligada Não Ordenada] [ 24 ] | [ C/C++] ( /src/c/ListaLigadaNaoOrdenada.c ) | Java | Python | Go | Ruby | Javascript | Pascal |
45
45
| Lista Sequencial Ordenada | [ C/C++] ( /src/c/ListaSequencialOrdenada.c ) | Java | [ Python] ( /src/python/lista_sequencial_ordenada.py ) | Go | Ruby | Javascript | Pascal |
Original file line number Diff line number Diff line change
1
+ class Node
2
+ attr_accessor :data , :next
3
+ def initialize ( data )
4
+ @data = data
5
+ @next = nil
6
+ end
7
+ end
8
+
9
+ class LinkedList
10
+ def initialize
11
+ @head = nil
12
+ end
13
+
14
+ def append ( data )
15
+ if @head . nil?
16
+ @head = Node . new ( data )
17
+ else
18
+ find_tail . next = Node . new ( data )
19
+ end
20
+ end
21
+
22
+ def find_tail
23
+ current_tail = @head
24
+ until current_tail . next . nil?
25
+ current_tail = current_tail . next
26
+ end
27
+ return current_tail
28
+ end
29
+
30
+ def find_before_node ( value )
31
+ current = @head
32
+ until current . next . data == value
33
+ current = current . next
34
+ end
35
+ return current
36
+ end
37
+
38
+ def delete ( value )
39
+ if @head . data == value
40
+ @head = @head . next
41
+ else
42
+ target = find ( value )
43
+ before = find_before_node ( value )
44
+ before . next = target . next
45
+ end
46
+ end
47
+
48
+ def find ( value )
49
+ current = @head
50
+ until current . data == value
51
+ current = current . next
52
+ end
53
+ current
54
+ end
55
+
56
+ def insert_after ( target , value )
57
+ current = find ( target )
58
+ temp = current . next
59
+ current . next = Node . new ( value )
60
+ current . next . next = temp
61
+ end
62
+
63
+ def print_list
64
+ current = @head
65
+ puts "List: "
66
+ until current . nil?
67
+ print "#{ current . data } "
68
+ current = current . next
69
+ end
70
+ end
71
+ end
72
+
73
+ list = LinkedList . new
74
+ list . append ( 10 )
75
+ list . append ( 20 )
76
+ list . append ( 30 )
77
+ list . insert_after ( 20 , 22 )
78
+ list . print_list
79
+ list . delete ( 30 )
80
+ list . print_list
You can’t perform that action at this time.
0 commit comments