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

Linked List order #1743

Closed
NeimadTL opened this issue Mar 11, 2025 · 2 comments
Closed

Linked List order #1743

NeimadTL opened this issue Mar 11, 2025 · 2 comments

Comments

@NeimadTL
Copy link
Contributor

NeimadTL commented Mar 11, 2025

Hi,

I was working on the simple linked list exercise and I couldn't help to wonder whether this assertion, which reads:

  def test_list_multiple_to_array
    skip
    list = SimpleLinkedList.new
    first = Element.new(1)
    second = Element.new(2)
    third = Element.new(3)
    list.push(first).push(second).push(third)
    assert_equal [3, 2, 1], list.to_a
  end

was correct?

In my opinion, when adding an element to the list with the following code:

list = SimpleLinkedList.new
first = Element.new(1)
second = Element.new(2)
third = Element.new(3)
list.push(first).push(second).push(third)

I should get that :
=> [1, 2, 3]

in other word the assertion should be this:
assert_equal [1, 2, 3], list.to_a

I haven't finished the exercise yet but I'm curious to get your opinion on it. Thank you.

Conversation on the forums located here.

@kotp
Copy link
Member

kotp commented Mar 11, 2025

Hello. I would do two things:

  • Get the exercise to pass, if you can
  • Request mentoring and discuss it with a mentor.

This will help solidify your understanding and then you will have your answer in regard to this PR if it should exist or not.

Note: I have edited your message to provide the context (keeping the link, though) so that no one needs to click out to get the value of the perceived problem.

@NeimadTL
Copy link
Contributor Author

Hey @kotp,

Thanks for editing.

I eventually got the exercise to pass but there are missing parts (list's head, next element and size).

Regarding the issue I raised:

  1. I when I read the code list.push(first).push(second).push(third) I naturally think that element are going to be inserted at the end of list and not at the beginning as the exercise "expects/forces" the student to do it (and there's nothing wrong with that at all).
  2. I was not aware that one could implement linked list that way, meaning inserting at the beginning UNLESS you add an index to specify it.

Appreciate your feedback, thank you and will ask mentoring.

@exercism exercism deleted a comment from github-actions bot Mar 11, 2025
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

No branches or pull requests

2 participants