Ça compile pas.
Corrections pour ça compile et test:
Plusieurs boucles infi et des soucis avec les }
.
diff --git a/simple-linked-list/src/lib.rs b/simple-linked-list/src/lib.rs
index 7702e68..07cd049 100644
--- a/simple-linked-list/src/lib.rs
+++ b/simple-linked-list/src/lib.rs
@@ -1,4 +1,4 @@
-use std::{clone, fs::OpenOptions, iter::FromIterator};
+use std::iter::FromIterator;
pub struct SimpleLinkedList<T> {
head: Option<Box<Node<T>>>,
@@ -11,9 +11,7 @@ struct Node<T> {
impl<T> SimpleLinkedList<T> {
pub fn new() -> Self {
- Self{
- head: None
- }
+ Self { head: None }
}
// You may be wondering why it's necessary to have is_empty()
@@ -25,7 +23,6 @@ impl<T> SimpleLinkedList<T> {
pub fn is_empty(&self) -> bool {
self.head.is_none()
}
-
/* J'ai essayé de faire un parcour de liste mais ça n'a rien donné.
pub fn len(&self) -> usize {
@@ -39,16 +36,16 @@ impl<T> SimpleLinkedList<T> {
}
count
}
- J'ai aussi essayer de voir l'implémentation d'un itérateur mais je me suis tourné par défaut
+ J'ai aussi essayer de voir l'implémentation d'un itérateur mais je me suis tourné par défaut
sur cette solution qui est certe, très moche mais qui "marche" */
-
pub fn len(&self) -> usize {
let mut count: usize = 0;
let iter = &self.head;
- while let Some(node) = iter{
+ while let Some(node) = iter {
count = count + 1;
&node.next;
+ unimplemented!("Infinite Loop")
}
count
}
@@ -59,11 +56,10 @@ impl<T> SimpleLinkedList<T> {
On ne peut pas "déréférencer" self.head grâce à .as_ref() ou autre. *de ce que j'ai compris*
*/
pub fn push(&mut self, _element: T) {
- let node: Box<Node<T>> =
- Box::new(Node {
+ let node: Box<Node<T>> = Box::new(Node {
data: _element,
next: self.head.take(),
- });
+ });
self.head = Some(node);
}
@@ -73,7 +69,7 @@ impl<T> SimpleLinkedList<T> {
grâce à self.head.take().unwrap() qu'on place dans une nouvelle node.
Puis on décale la tête de la liste a la node suivante node.next.take().
Pour fini on retourne la valeur contenue dans la node (node.data)*/
-
+
pub fn pop(&mut self) -> Option<T> {
match self.head {
None => None,
@@ -91,30 +87,29 @@ impl<T> SimpleLinkedList<T> {
pub fn peek(&self) -> Option<&T> {
if self.head.is_none() {
- return None
+ return None;
}
- return Some(&self.head.as_ref().unwrap().data)
+ return Some(&self.head.as_ref().unwrap().data);
}
pub fn rev(mut self) -> SimpleLinkedList<T> {
- if self.head.is_none(){
- self
- }else {
- let mut precedent = None;
- let mut actuelle = self.head.take();
- while actuelle.is_some(){
- let suivant = actuelle.as_mut().unwrap().next.take();
- actuelle.as_mut().unwrap().next = precedent.take();
- precedent = actuelle.take();
- actuelle = suivant;
+ unimplemented!("Infinite loooop");
+ if self.head.is_none() {
+ self
+ } else {
+ let mut precedent = None;
+ let mut actuelle = self.head.take();
+ while actuelle.is_some() {
+ let suivant = actuelle.as_mut().unwrap().next.take();
+ actuelle.as_mut().unwrap().next = precedent.take();
+ precedent = actuelle.take();
+ actuelle = suivant;
+ }
+ self
}
- self
}
}
-
-
-
impl<T> FromIterator<T> for SimpleLinkedList<T> {
fn from_iter<I: IntoIterator<Item = T>>(_iter: I) -> Self {
unimplemented!()
@@ -137,4 +132,3 @@ impl<T> From<SimpleLinkedList<T>> for Vec<T> {
unimplemented!()
}
}
-}
\ No newline at end of file
diff --git a/simple-linked-list/tests/simple-linked-list.rs b/simple-linked-list/tests/simple-linked-list.rs
index f190ea6..c89f8b5 100644
--- a/simple-linked-list/tests/simple-linked-list.rs
+++ b/simple-linked-list/tests/simple-linked-list.rs
@@ -7,7 +7,6 @@ fn test_new_list_is_empty() {
}
#[test]
-#[ignore]
fn test_push_increments_length() {
let mut list: SimpleLinkedList<u32> = SimpleLinkedList::new();
list.push(1);
@@ -17,7 +16,6 @@ fn test_push_increments_length() {
}
#[test]
-#[ignore]
fn test_pop_decrements_length() {
let mut list: SimpleLinkedList<u32> = SimpleLinkedList::new();
list.push(1);
@@ -29,7 +27,6 @@ fn test_pop_decrements_length() {
}
#[test]
-#[ignore]
fn test_is_empty() {
let mut list: SimpleLinkedList<u32> = SimpleLinkedList::new();
assert!(list.is_empty(), "List wasn't empty on creation");
@@ -61,7 +58,6 @@ fn test_is_empty() {
}
#[test]
-#[ignore]
fn test_pop_returns_head_element_and_removes_it() {
let mut list: SimpleLinkedList<u32> = SimpleLinkedList::new();
list.push(1);
@@ -72,7 +68,6 @@ fn test_pop_returns_head_element_and_removes_it() {
}
#[test]
-#[ignore]
fn test_peek_returns_reference_to_head_element_but_does_not_remove_it() {
let mut list: SimpleLinkedList<u32> = SimpleLinkedList::new();
assert_eq!(list.peek(), None, "No element should be contained in list");
@@ -88,7 +83,6 @@ fn test_peek_returns_reference_to_head_element_but_does_not_remove_it() {
}
#[test]
-#[ignore]
fn test_from_slice() {
let mut array = vec!["1", "2", "3", "4"];
let mut list: SimpleLinkedList<_> = array.drain(..).collect();
@@ -99,7 +93,6 @@ fn test_from_slice() {
}
#[test]
-#[ignore]
fn test_reverse() {
let mut list: SimpleLinkedList<u32> = SimpleLinkedList::new();
list.push(1);
@@ -113,7 +106,6 @@ fn test_reverse() {
}
#[test]
-#[ignore]
fn test_into_vector() {
let mut v = Vec::new();
let mut s = SimpleLinkedList::new();