Skip to content

Add practice exercise for linked list #566

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

Closed
vaeng opened this issue Mar 1, 2023 · 8 comments · Fixed by #567
Closed

Add practice exercise for linked list #566

vaeng opened this issue Mar 1, 2023 · 8 comments · Fixed by #567
Assignees

Comments

@vaeng
Copy link
Contributor

vaeng commented Mar 1, 2023

The #12in23 challenge asks to do the linked-list exercise, which is currently not implemented and should be added during the month of March.

@vaeng vaeng self-assigned this Mar 1, 2023
@siebenschlaefer
Copy link
Contributor

Does the self-assignment mean you're working on it?
Otherwise I'll give it a try.

@vaeng vaeng linked a pull request Mar 1, 2023 that will close this issue
5 tasks
@vaeng
Copy link
Contributor Author

vaeng commented Mar 1, 2023

Does the self-assignment mean you're working on it? Otherwise I'll give it a try.

Yes, I have started to add some basic files, but have not yet done more (the instruction are taken from the Go track). Feel free to add more.

One of the thoughts I wanted to discuss was the split with .cpp and header files. And if we should move the "easy" exercises to "cpp-only" to nudge the students slowly to that topic on later exercises that need more organization.

@siebenschlaefer
Copy link
Contributor

Some notes:

  • push(), pop(), unshift(), and shift() are mandatory, delete() and count() are optional. Do we want them?
    I'd vote yes but then we need an additional markdown file that describes them, similarly to the description of the mandatory functions.
  • The tests leave it to the tracks whether delete() should return the first or last matching element (or leave it unspecified). What do we want? I'd vote first.
  • Do we want other C++-specific things? Should the linked-list class be a class template? Do we want iterators? Do we want an exception if pop() or shift() get called on an empty list? Should count() be named size()? Tracks are allowed to add/change things when its reasonable and idiomatic.

Attached is a Python script create_tests.txt that reads the canonical-data.json (from the problem-specification repository) and prints the contents of the linked_list_test.cpp. (It ends with .txt because GitHub does not allow attaching .py files.)

@vaeng
Copy link
Contributor Author

vaeng commented Mar 1, 2023

I think delete() is pretty interesting because you have to put in some more thoughts than just dropping elements. In my opinion, it should return the first match.

count() might be nice, but I don't think it adds a lot.

Iterators, class templates and exceptions should depend on where the exercise is placed in the syllabus tree. We should not add all to make it not too complex. Unless we implement simple-list as well?

Thanks for the script! That seems super handy.

@vaeng
Copy link
Contributor Author

vaeng commented Mar 1, 2023

You do make some very good points. I think we should definitely do a simple-linked-list first. The way I see it, it is intended to have elements with int-data, push, pop, size, reverse and an array conversion. That would pave the way to have the "advanced" version as class template with iterators. What do you think @siebenschlaefer?

@siebenschlaefer
Copy link
Contributor

I just wanted to list these considerations explicitly so that others can weigh in.
I'm completely fine with a simple non-template LinkedList class without exceptions that has these six methods.

From a mentoring perspective I expect the conversations to the about memory management (naked new and raw pointers versus smart pointers a non-recursive deletion), about the general approach of the implementation (first/last pointers or a dummy node), and about helper functions/DRY. At least that's my experience for the linked-list exercise on the C track.

@vaeng
Copy link
Contributor Author

vaeng commented Mar 1, 2023

That's very valuable insight. As the memory aspects with pointer management can be a bit intimidating, the related exercises should not do much else.

But, with the memory management questions mostly answered with the simple-list, we could dive into a nice iterator solution and make them useful via templates.

@vaeng
Copy link
Contributor Author

vaeng commented Mar 2, 2023

I added a new PR for the simple-linked-list: #570

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 a pull request may close this issue.

2 participants