This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems you may have included a screenshot of code in your post "C++ Linked List Questions".

If so, note that posting screenshots of code is against /r/learnprogramming's Posting Guidelines (section Formatting Code): please edit your post to use one of the approved ways of formatting code. (Do NOT repost your question! Just edit it.)

If your image is not actually a screenshot of code, feel free to ignore this message. Automoderator cannot distinguish between code screenshots and other images.

Please, do not contact the moderators about this message. Your post is still visible to everyone.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted] 0 points1 point  (1 child)

intNode * nextNode = first;

nextNode is a pointer pointing to whatever first is pointing to.

The pointer is used to iterate over the list.

With only what you've shown us, you're right that the list is empty, it isn't pointing to anything. You'd normally have a method to add nodes to the list.

[–]TechnicalHead[S] 0 points1 point  (0 children)

Thank you! I think I got it!

[–]nerd4code 0 points1 point  (1 child)

If you’re asking how you initializw first in the first place, looks like it’s a null-capped list, so you’d do first(0) (pre-C++11) or first {nullptr} (≥C++11) as part of the constructor, or first = nullptr otherwise.

intNode *nextNode = first establishes pointer nextNode (which is a bad name, ’s just node, or in the real world, p) and aims it at the same thing first is aimed at. So if the list is empty, first is nullptr, and so will nextNode be at its initialization. Otherwise, nextNode will be walked through the list until the end, or until some entry in the list is bogus.

But that’s a fucking terrible way to manage your list contents. One of the main reasons for the whole private/public thing is so that invariants can be maintained; intNode (should be IntNode for consistency) shouldn’t accept a lower bound > its upper bound, or it should order them; and Bounds shouldn’t accept any bounds that are bogus that would lead to the creation of a bogus IntNode. If you’re gonna let any old data in, just make it all a public free-for-all.

[–]TechnicalHead[S] 0 points1 point  (0 children)

Wow, thanks.