Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

YannBonaudo
Copy link
Member

No description provided.

@YannBonaudo YannBonaudo requested a review from cbonaudo September 1, 2022 13:31
}

pub fn len(&self) -> usize {
unimplemented!()
self.len
Copy link
Member

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;
Copy link
Member

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),
Copy link

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)
Copy link

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();
Copy link

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) {
Copy link

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> {
Copy link

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,
Copy link

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,
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants