954,198 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem kicking my but!!! can anybody help?

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.

zebra59
Newbie Poster
7 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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

zebra59
Newbie Poster
7 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

>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 ;)

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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.


I fix the link part any responses

zebra59
Newbie Poster
7 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
>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

zebra59
Newbie Poster
7 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

>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?

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

>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;
<strong>fill in this line of the missing statement.</strong>
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!:)

zebra59
Newbie Poster
7 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

>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?

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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?
zebra59
Newbie Poster
7 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
 

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 linkingq 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 anew 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.

dohpaz42
Newbie Poster
16 posts since Jun 2010
Reputation Points: 12
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You