Timeline for Linked list implementation correctness
Current License: CC BY-SA 3.0
19 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 23, 2017 at 12:40 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Jul 1, 2014 at 0:19 | history | edited | Yuushi | CC BY-SA 3.0 |
Added copy and swap stuff
|
Jun 30, 2014 at 22:59 | comment | added | Yuushi | @LokiAstari Feel free to talk about smart pointers, I think my post is long enough already. I have mentioned the rule of three; it is in bold. If you feel that isn't prominent enough, you can edit my post if you'd like. Finally, I'm fully aware of copy and swap, and I should have mentioned it, I'll edit it in. | |
Jun 30, 2014 at 22:46 | comment | added | Michael Naumov | also should I implement move ctor and move assignment op for linked list? | |
Jun 30, 2014 at 22:46 | comment | added | Michael Naumov | @Yuushi hmm here they are fine using underscore prefixes: msdn.microsoft.com/en-us/library/dd293665.aspx No big deal to me though, just want to learn it right way from the start. | |
Jun 30, 2014 at 20:24 | comment | added | Loki Astari | The three stages in assignment are: 1) Copy without modifying state of the destination object (as the act of copying can generate an exception and you want to make sure you put1 your object in a bad state). 2) Swap out the old value with the new value (in an exception safe manor) 3) Delete/Free the old value. Does not matter if it fails as (2) made sure the state of the object is good. | |
Jun 30, 2014 at 19:59 | vote | accept | Michael Naumov | ||
Jun 30, 2014 at 19:24 | comment | added | Loki Astari | Couple of issues. 1) C++ has fine grain deterministic garbage collection (smart pointers). Any conversation on new and delete should mention this. 2) When talking about the compiler generated methods you should mention the "Rule of Three" Please make it more prominent at the top of your discussion. 3) Your implementation of assignment operator is outdated (and bad (never alter state (delete) until you have the value to swap into its place)). The modern way of doing this is via "Copy And Swap idiom" | |
Jun 30, 2014 at 7:59 | comment | added | Yuushi | If you want to be able to use the standard library algorithms, yes. | |
Jun 30, 2014 at 7:44 | comment | added | Michael Naumov | @Yuushi so I will need to implement iterator and begin()/end() functions in my list for the search function to work? | |
Jun 30, 2014 at 6:14 | comment | added | Yuushi | See my update as for how a search would generally work over a list type in C++. | |
Jun 30, 2014 at 6:13 | history | edited | Yuushi | CC BY-SA 3.0 |
added 1147 characters in body
|
Jun 30, 2014 at 6:05 | comment | added | Yuushi |
No, you don't need to define a destructor in your Node class, as T is a value type.
|
|
Jun 30, 2014 at 5:40 | comment | added | Michael Naumov | my other question is do I need to implement destructor in the Node class? What's the best way to delete value or should I even do that because it's defined as reference in my code? | |
Jun 30, 2014 at 5:32 | comment | added | Michael Naumov | @Yuushi ok but if I search by value and return value, what's the point of the search? | |
Jun 30, 2014 at 5:22 | comment | added | Yuushi |
@MichaelNaumov You'd search for it via the value, so something like value == search_value .
|
|
Jun 30, 2014 at 5:12 | comment | added | Michael Naumov | thank you for your review, yeah I am aware of delete, I just somehow wasn't sure whether to include it inside the datastructure or call it outside, but I see now. However if I remove a key how would I search for node or what is the point of find function in the first place if I am just going to pass data as a parameter? | |
Jun 30, 2014 at 5:10 | comment | added | Jamal |
Minor point: you could also mention that getCount() should be const .
|
|
Jun 30, 2014 at 4:55 | history | answered | Yuushi | CC BY-SA 3.0 |