I have this problem that I can't figure out, I can't figure out the line
statement that needs to go in.
Here's the problem

struct NodeType
{
    int data;
    NodeType* p;
};

NodeType* p;
NodeType* q;

p = new NodeType;
p->data = 18;
q = new NodeType;
q->data = 32;
                                          <--   statement missing here
q->link = NULL;

I've look @ ever example and went over the chapter on linked structures / linked list, however I just can't figure it out!!! Help
thanks for your time.

p->link = q; , perhaps? It's hard to say with your little uninformative guessing game.

sorry but that all the info that i have, however thanks for you rresponse

> q->link = NULL;
Your struct doesn't contain a member called link ?

>sorry but that all the info that i have
No wonder you can't figure it out, you don't even know what the problem is!

>Your struct doesn't contain a member called link ?
Yea, I saw that too...no, really. :o ;)

I fix the link part any responses

>I fix the link part any responses
Um, good for you? You still haven't specified enough of a problem to be solvable. You tell us what the code is supposed to be doing, and we'll tell you why it isn't working. Until then, get used to not having any useful responses.

>I fix the link part any responses
Um, good for you? You still haven't specified enough of a problem to be solvable. You tell us what the code is supposed to be doing, and we'll tell you why it isn't working. Until then, get used to not having any useful responses.

If I knew then I wouldn't be asking for your help, now would I ?
Buit thanks for looking anyway

>If I knew then I wouldn't be asking for your help, now would I ?
There's a significant difference between knowing the problem and knowing the cause of the problem. Not the least of which being that I'm talking about the former and you're talking about the latter. Do you go to a doctor and just tell him to heal you? Do you go to a mechanic and tell him to fix any problems he finds? No, you go to a doctor when you're injured or ill, and can tell him where it hurts. You go to a mechanic when your car makes a funny noise that you can describe to the mechanic.

I'm the doctor, tell me where it hurts. I'm the mechanic, describe the noise you're hearing. Then I'll use my expertise to help you correct the problem. Now, what part of that are you having trouble understanding?

>If I knew then I wouldn't be asking for your help, now would I ?
There's a significant difference between knowing the problem and knowing the cause of the problem. Not the least of which being that I'm talking about the former and you're talking about the latter. Do you go to a doctor and just tell him to heal you? Do you go to a mechanic and tell him to fix any problems he finds? No, you go to a doctor when you're injured or ill, and can tell him where it hurts. You go to a mechanic when your car makes a funny noise that you can describe to the mechanic.

I'm the doctor, tell me where it hurts. I'm the mechanic, describe the noise you're hearing. Then I'll use my expertise to help you correct the problem. Now, what part of that are you having trouble understanding?

:?:again, like I said before, I needed to fill in the missing statement, however, I couldn't figure it out.

here is the question that was given to me.

struct NodeType
{
  int data;
  NodeType* link;
};
NodeType* p;
NodeType* q;

p = new NodeType;
p -> data = 18;
q = new NodeType;
q -> data = 32;
[B]fill in this line of the missing statement.[/B]
q-> link = NULL;

that was my question, I didn't know if they are looking for. Thats why I purposed the question, maybe just maybe one of the experts out there could help me out.

Thanks for you r time anyway.

Have a good day!:)

>maybe just maybe one of the experts out there could help me out.
No, sorry. We can make educated guesses (as I've already done), but you're simply not providing enough information. Go back to whoever gave you that code and tell them that you can't fill in a missing statement when you don't even remotely know how the statement is supposed to fit into the rest of the code. Here, this is a perfectly valid and correct answer to your question:

p = new NodeType;
p -> data = 18;
q = new NodeType;
q -> data = 32;

cout<<"Narue is kewl!\n";

q-> link = NULL;

Don't you see how absurd your request is?

Yes, and I will again thanks for your time.

>maybe just maybe one of the experts out there could help me out.
No, sorry. We can make educated guesses (as I've already done), but you're simply not providing enough information. Go back to whoever gave you that code and tell them that you can't fill in a missing statement when you don't even remotely know how the statement is supposed to fit into the rest of the code. Here, this is a perfectly valid and correct answer to your question:

p = new NodeType;
p -> data = 18;
q = new NodeType;
q -> data = 32;

cout<<"Narue is kewl!\n";

q-> link = NULL;

Don't you see how absurd your request is?

What Narue is trying to say is we can't just fill in any old line of code, we have to know what the code is supposed to accomplish, then we are able to figure out what the line is supposed to be.

In other words,
What is that line supposed to do? What makes you think a line is needed? When we know that, we can figure out what the line is.

I have this problem that I can't figure out, I can't figure out the line
statement that needs to go in.
Here's the problem

struct NodeType
{
    int data;
    NodeType* link;
};

NodeType* p;
NodeType* q;

p = new NodeType;
p->data = 18;
q = new NodeType;
q->data = 32;
                                          <--   statement missing here
q->link = NULL;

I've look @ ever example and went over the chapter on linked structures / linked list, however I just can't figure it out!!! Help
thanks for your time.

Since you are talking about linked structures, the only guess that I can fathom is the missing line of code that you are asking about has to do with linking q to p. Since the link member of NodeType is a pointer to another NodeType, it would stand to reason that you need to assign the q pointer to the link pointer contained in p. i.e.,

// ... snipped code
q = new NodeType;
q->data = 32;
p->link = q; // Your "missing statement"
q->link = NULL;

Since this is a linked structure, anytime you create a new NodeType, you will need to ensure to assign that new NodeType to the previous node. Also, because you are using the new operator, you will also need to make sure that you iterate back through your linked structure and delete each node you've created. While this might just be an example, it is always good practice to get into the habit of freeing the memory you reserve. Remember: use delete for each new, and delete [] for each new []. You cannot delete something that you didn't allocate using new/new []. Not doing so will certainly cause memory leaks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.