File tree 2 files changed +52
-1
lines changed
2 files changed +52
-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 | JS | Pascal | Swift | Rust |
40
40
| [ Grafo] [ 20 ] | [ C/C++] ( ./src/c/Grafos.c ) | Java | Python | Go | Ruby | JS | Pascal | Swift | Rust |
41
41
| [ Lista Circular Ligada] [ 52 ] | [ C/C++] ( ./src/c/ListaCircularLigada.c ) | Java | [ Python] ( ./src/python/lista_encadeada_circular.py ) | Go | Ruby | JS | Pascal | Swift | Rust |
42
- | [ Lista Encadeada] [ 22 ] | C/C++ | Java | [ Python] ( ./src/python/lista_encadeada.py ) | Go | [ Ruby] ( ./src/ruby/Lista_encadeada.rb ) | [ JS] ( ./src/javascript/ListaSimplesmenteEncadeada.js ) | Pascal | Swift | Rust |
42
+ | [ Lista Encadeada] [ 22 ] | C/C++ | Java | [ Python] ( ./src/python/lista_encadeada.py ) | Go | [ Ruby] ( ./src/ruby/Lista_encadeada.rb ) | [ JS] ( ./src/javascript/ListaSimplesmenteEncadeada.js ) | Pascal | Swift | [ Rust] ( ./src/rust/linked_list.rs ) |
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] ( ./src/ruby/Lista_duplamente_encadeada.rb ) | [ JS] ( ./src/javascript/ListaDuplamenteEncadeada.js ) | Pascal | Swift | Rust |
44
44
| [ Lista Ligada Não Ordenada] [ 24 ] | [ C/C++] ( ./src/c/ListaLigadaNaoOrdenada.c ) | Java | Python | [ Go] ( src/go/listasequencialnaoordenada/listaSequencialNaoOrdenada.go ) | Ruby | JS | Pascal | Swift | Rust |
45
45
| Lista Sequencial Ordenada | [ C/C++] ( ./src/c/ListaSequencialOrdenada.c ) | Java | [ Python] ( ./src/python/lista_sequencial_ordenada.py ) | [ Go] ( src/go/listasequencialordenada/listaSequencialOrdenada.go ) | Ruby | JS | Pascal | Swift | Rust |
Original file line number Diff line number Diff line change
1
+ #[ derive( Debug ) ]
2
+ struct Node < T > {
3
+ data : T ,
4
+ next : Option < Box < Node < T > > > ,
5
+ }
6
+
7
+ #[ derive( Debug ) ]
8
+ struct LinkedList < T > {
9
+ head : Option < Box < Node < T > > > ,
10
+ size : usize ,
11
+ }
12
+
13
+ impl < T > LinkedList < T > {
14
+ pub fn new ( ) -> Self {
15
+ LinkedList {
16
+ head : None ,
17
+ size : 0 ,
18
+ }
19
+ }
20
+
21
+ pub fn len ( & self ) -> usize {
22
+ self . size
23
+ }
24
+
25
+ pub fn push ( & mut self , data : T ) {
26
+ self . head = Some ( Box :: new ( Node {
27
+ data : data,
28
+ next : self . head . take ( ) ,
29
+ } ) ) ;
30
+ self . size += 1 ;
31
+ }
32
+
33
+ pub fn pop ( & mut self ) -> Option < T > {
34
+ self . head . take ( ) . map ( |h| {
35
+ self . head = h. next ;
36
+ self . size -= 1 ;
37
+ h. data
38
+ } )
39
+ }
40
+ }
41
+
42
+ fn main ( ) {
43
+ let mut linked_list: LinkedList < u16 > = LinkedList :: new ( ) ;
44
+ linked_list. push ( 1 ) ;
45
+ linked_list. push ( 2 ) ;
46
+ linked_list. push ( 3 ) ;
47
+ println ! ( "{:#?}" , linked_list) ;
48
+ linked_list. pop ( ) ;
49
+ println ! ( "{:#?}" , linked_list) ;
50
+ println ! ( "Linked List Length: {}" , linked_list. len( ) ) ;
51
+ }
You can’t perform that action at this time.
0 commit comments