|
|
I don't think it's a good idea. It would prohibit the use of end() on an empty list. |
The two exercises I referenced are talking about a doubly-linked list. |
This is what I was thinking with the above code: ... |
So what would you suggest, then? |
since the one-past-the-end node would never be used, would it be okay to leave some garbage value stored in there? |
1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(68): error C2187: syntax error: '{' was unexpected here |
So I just have a member of the class that represents the one-past-the-end node and return that in the end() function? |
What did you say about prohibiting the use of end() on an empty list, though, and how do I fix that? |
I have this error on line 68 |
And what else am I doing wrong aside from (assuming there's still something wrong, which there might be)? |
1>------ Build started: Project: real_linked_list, Configuration: Debug Win32 ------ 1>main.cpp 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): error C2327: 'list<int>::one_past_end': is not a type name, static, or enumerator 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(146): note: see reference to function template instantiation 'auto &list<int>::iterator::operator ++(void)' being compiled 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(50): note: see reference to function template instantiation 'Iter high<list<int>::iterator>(Iter,Iter)' being compiled 1> with 1> [ 1> Iter=list<int>::iterator 1> ] 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(42): note: see reference to class template instantiation 'list<int>' being compiled 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): error C2065: 'one_past_end': undeclared identifier 1>Done building project "real_linked_list.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
The one_past_end node is a pointer because the list class is using Link pointers as nodes. Why, is that not good? |
I'll make the changes you mentioned for begin and end. [...] I had it in begin(), but should I keep that or take it out? |
How do I make sure that my ++ operators don't go past the last node? I can't use one_past_end in there because it's not a member of list::iterator. |
So there are imaginary nodes that the pointers are pointing to? Because I only made pointers to them. |
|
|
But as for traversing back to the previous node from one_past_end: I tried that and saw that I actually can do it. Look at my user code on the Gist. That does actually work. |
|
|
if (!new_node->succ)
, but with the current conditional check there are no leaks at least. But is it fine aside from that as well or could there be other problems?list(size_type count);
inside the class definition. Visual Leak Detector read settings from: C:\Program Files (x86)\Visual Leak Detector\vld.ini Visual Leak Detector Version 2.5.1 installed. 100 200 300 400 500 | Size of lst2 is 1 lst2: 0 lst in reverse: 100 200 300 400 500 The highest value was 500 Please enter a character to exit l No memory leaks detected. Visual Leak Detector is now exiting. Press any key to continue . . . |
Don't I have to point first and last at one_past_end? |
Right now it's still inserting after the current node, so I don't need to worry about a node being insert at the front. |
For now I need help with the constructor that has the signature list(size_type count); inside the class definition. |
new_node->succ->prev = new_node;
Should it be changed to new_node->prev->succ = new_node;
?
|
|
|
|
|
|
last->succ = new_node;
line, and triggers a breakpoint with the message saying that **last** is nullptr). I fixed that by putting this code in push_back:
|
|
|
|
Visual Leak Detector read settings from: C:\Program Files (x86)\Visual Leak Detector\vld.ini Visual Leak Detector Version 2.5.1 installed. 100 200 300 400 500 | Size of lst2 is 1 lst2: 0 lst in reverse: 100 200 300 The highest value was 500 Please enter a character to exit k No memory leaks detected. Visual Leak Detector is now exiting. Press any key to continue . . . |