Nodes and Linked List

K

KL

I am so confused. I am working on a project for my class, and I can't
remember how to do Nodes and linked lists.

I have the following bit of code but don't know how to proceed from
here. If someone could help direct me to the right answer, not just
give me the code, I would appreciate it:

class Node {
public:
Node( );
Node( int t );
Node( int t, Node *n );
friend class List;
friend ostream& operator<<(ostream&, const Node&);
friend ostream& operator<<(ostream&, const List&);
private:
int time;
int count;
Node *next;
};
/*
class List {
public:
List( );
bool insert(int);
friend ostream& operator<<(ostream& os, const List&);
private:
Node *head;
};
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

I am so confused. I am working on a project for my class, and I can't
remember how to do Nodes and linked lists.

I have the following bit of code but don't know how to proceed from
here. If someone could help direct me to the right answer, not just
give me the code, I would appreciate it:

There's a topic called 'Inserting a number into a linked list in
ascending order' which can give you some hints. A quick google should
give you lots of examples, and Wikipedia will probably contain some
sample code too.
 
M

Michael

I am so confused. I am working on a project for my class, and I can't
remember how to do Nodes and linked lists.

Walk away from your computer. Far away. Draw on a piece of paper what
you want to do. Not in code, but in picture format, where nodes are
rectangles, and pointers are arrows from one rectangle to another.
Work out the logic first that way. Maybe write some pseudo-code on
your piece of paper. (In other words, take notes about how you solve
the problem.)

Once you're clear on the logic (which is the hard part), then go back
to your computer and translate that logic into code (which is the other
hard part, since C++ is still new to you). At that point, if you run
into syntax problems or whatever, post a question. Something along the
lines of "here's the logic I'm trying to implement. Here's the code I
have so far. What's wrong?"

Michael
 
M

Michal Nazarewicz

KL said:
I am so confused. I am working on a project for my class, and I can't
remember how to do Nodes and linked lists.

Linked lists are described nicely on Wikipedia
<URL:http://en.wikipedia.org/>.

Next time try searching for your answer in Google or Wikipedia before
posting it - you'll get your answer faster that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top