-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yann Simple linked list #5
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
pub fn len(&self) -> usize { | ||
unimplemented!() | ||
self.len |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
je pense que le fait de mettre la len comme propriété et de la modifier manuellement est débattable, et que ce serait peut-être plus pertinent de la calculer pendant la fonction len, en allant sur chaque item.
} | ||
|
||
pub fn rev(self) -> SimpleLinkedList<T> { | ||
unimplemented!() | ||
let mut node = self; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On appelle ça un node, mais en fait c'est la liste complète, non ?
} | ||
|
||
pub fn peek(&self) -> Option<&T> { | ||
unimplemented!() | ||
match &self.head { | ||
Some(head) => return Some(&head.element), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.as_ref() ?
fn from(mut linked_list: SimpleLinkedList<T>) -> Vec<T> { | ||
let mut new_vec = Vec::new(); | ||
while let Some(element) = linked_list.pop() { | ||
new_vec.insert(0, element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insert décale tout les éléments suivants d’un cran vers la droite. Ce serait plus efficace d’itérer dans l’ordre de linked_list pour les insérer dans l’ordre également
fn from(mut _linked_list: SimpleLinkedList<T>) -> Vec<T> { | ||
unimplemented!() | ||
fn from(mut linked_list: SimpleLinkedList<T>) -> Vec<T> { | ||
let mut new_vec = Vec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pour être un chouilla plus efficace tu peux initialiser le vecteur cible avec Vec::with_capacity, étant donné que tu connais déjà la taille du vecteur à créer
} | ||
|
||
pub fn push(&mut self, _element: T) { | ||
unimplemented!() | ||
pub fn push(&mut self, element: T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En théorie push est censé rajouter des éléments à la suite de la liste si je ne dis pas de bêtise. Là ils sont insérés au début. Ça ne se voit pas parce que le test en question n’ajoute qu’un seul élément
pub fn push(&mut self, element: T) { | ||
let initial_head = self.head.take(); | ||
self.len += 1; | ||
self.head = Some(Box::new(Node::new(initial_head, element))) | ||
} | ||
|
||
pub fn pop(&mut self) -> Option<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
De même pour pop, je me demande si ça ne supprime pas les éléments en bout de chaine
self.len -= 1; | ||
return Some(head.element); | ||
} | ||
None => return None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Les return ne sont pas nécessaires
unimplemented!() | ||
match &self.head { | ||
Some(head) => return Some(&head.element), | ||
None => return None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Les returns ne sont pas nécessaires
No description provided.