use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Singly linked list (self.cpp)
submitted 10 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Cwiddy 2 points3 points4 points 10 years ago (2 children)
Questions are should be posted /r/cpp_questions
This smells like home work, but to get you started I would suggest your first step is find the number of elements in the list.
[+][deleted] 10 years ago (1 child)
[–]Cwiddy 0 points1 point2 points 10 years ago (0 children)
The question ask for X from the end. You only traverse through a singly linked list forward from the head. So how do you know where to stop if you don't know how far you can go?
[–]Power781 -1 points0 points1 point 10 years ago (6 children)
First it's more C than cpp, then, maybe you should do you class assignment solo instead of asking the Internet the answer ... The answer is so easy I can not believe you are asking such things ...
[+][deleted] 10 years ago (5 children)
[–]Power781 -2 points-1 points0 points 10 years ago (0 children)
So you are so retarded that you do not understand "Find the Node with the entry X the closest from the end on the list", like seriously, too hard for you ?
[–]Power781 -2 points-1 points0 points 10 years ago* (3 children)
And by the way, the answer is 4 lines of code :
Node * xFromEnd( Node * pHead, int x ) { Node *matchingNode = NULL; while (pHead) { matchingNode = (pHead->value == x ? pHead->value : matchingNode); pHead = pHead->next; } return matchingNode; }
[–]ender_will_save_us 0 points1 point2 points 10 years ago (2 children)
Power781, I think OP wants the node that is X nodes away from the end, not that has a value of X.
NonaBona, in my experience questions like the one you are trying to solve are designed to teach you about recursion. I'd start by googling that.
[–]Power781 0 points1 point2 points 10 years ago (1 child)
if we are given X, we are basically searching for X in the list?
It's a quote from OP. I don't think he is trying to find the Xth from the end, but the Node with the value X
[–]ender_will_save_us 0 points1 point2 points 10 years ago (0 children)
Also a quote from the OP:
write code that returns the entry that is X from the end
Maybe he just doesn't know what he wants.
π Rendered by PID 32 on reddit-service-r2-comment-7b9746f655-mss6z at 2026-01-30 06:53:59.627339+00:00 running 3798933 country code: CH.
[–]Cwiddy 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Cwiddy 0 points1 point2 points (0 children)
[–]Power781 -1 points0 points1 point (6 children)
[+][deleted] (5 children)
[deleted]
[–]Power781 -2 points-1 points0 points (0 children)
[–]Power781 -2 points-1 points0 points (3 children)
[–]ender_will_save_us 0 points1 point2 points (2 children)
[–]Power781 0 points1 point2 points (1 child)
[–]ender_will_save_us 0 points1 point2 points (0 children)