Thread: Double linked list error, help!

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    11

    Arrow Double linked list error, help!

    All set! Thanks!
    Last edited by raell; 03-07-2004 at 06:26 PM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>**node->right = temp;
    Try:
    >>node->right = temp;

    That should get you a little further, how far I don't know
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Okay, how about posting something that we can compile? As it is you have a super secret header file that defines types and functions. Your formatting is awful. Most notable is that cut/pasted and compiled you seem to be trying to define functions within main. Also, if you are going to mark pieces of code, do so with comments so that we don't have to remove every occurance before getting the code to compile.

    Here's a tip. Write a separate program that does the same thing with less fluff. If your problem is with the list then write a bare bones list. This way we don't end up wading through too much unnecessary code to find your problem. Do this and I'll look further than the first include directive.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    11
    Originally posted by Prelude
    Okay, how about posting something that we can compile? As it is you have a super secret header file that defines types and functions. Your formatting is awful. Most notable is that cut/pasted and compiled you seem to be trying to define functions within main. Also, if you are going to mark pieces of code, do so with comments so that we don't have to remove every occurance before getting the code to compile.

    Here's a tip. Write a separate program that does the same thing with less fluff. If your problem is with the list then write a bare bones list. This way we don't end up wading through too much unnecessary code to find your problem. Do this and I'll look further than the first include directive.
    As I mentioned before, half of this is in FLEX- So it makes it harder for me to explain, but yes I guess that would make them 'super secret header files'. If you want- I can include that
    part too, I thought it would over complicate things.

    My main question is what is incompatible in the statements that I marked off- because they seem like they should work. These are defined and used Only in the C program I included here, so therein lies the problem. I can't see it either, this is my first time using emacs, flex, ssh etc, so I'm a bit confused myself.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>My main question is what is incompatible in the statements

    >>**node->right = temp;
    You're trying to dereference the node pointer three times, which is invalid, you can only do it once. The two ways of doing this are:
    >>node->right
    (like I already showed you)
    Or
    >>(*node).right
    ... which is valid syntax, but is simply long hand for the first version.

    By doing **node->right, the ** is two deferences, and -> makes a third.

    Having said that, the assignment is incorrect anyway, as "right" is a pointer to a struct element, whereas "temp" is a pointer to a struct wordnode.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    11
    Originally posted by Hammer
    >>My main question is what is incompatible in the statements

    >>**node->right = temp;
    You're trying to dereference the node pointer three times, which is invalid, you can only do it once. The two ways of doing this are:
    >>node->right
    (like I already showed you)
    Or
    >>(*node).right
    ... which is valid syntax, but is simply long hand for the first version.

    By doing **node->right, the ** is two deferences, and -> makes a third.

    Having said that, the assignment is incorrect anyway, as "right" is a pointer to a struct element, whereas "temp" is a pointer to a struct wordnode.
    The last bit clears things up.
    The only reason the **'s are there is to show you where I'm having issues. It's Not in the code itself.

    "right" is a pointer to a struct element, whereas "temp" is a pointer to a struct wordnode. [/QUOTE] -- This is what I was looking for (not how awful my code is formatted), you've answered my question,
    thank you!!

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>It's Not in the code itself.
    Doh ! Wasted my time there then

    I suggest next time you highlight a line, use text that is actually commented out, so that people like me don't get confused! For example:
    Code:
    /* PROBLEM HERE */ temp->left = node;
    /* PROBLEM HERE */ node->right = temp;
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    Dec 2003
    Posts
    11
    Originally posted by Hammer
    >>It's Not in the code itself.
    Doh ! Wasted my time there then

    I suggest next time you highlight a line, use text that is actually commented out, so that people like me don't get confused! For example:
    Code:
    /* PROBLEM HERE */ temp->left = node;
    /* PROBLEM HERE */ node->right = temp;
    Good idea! Thanks again

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >If you want- I can include that
    Read my second paragraph for details of what you should do to get better help.

    >because they seem like they should work
    Why do you think so? temp is a pointer to wordnode yet temp->right and temp->left are pointers to element. It's not terribly surprising that you are having issues with assignment.
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Dec 2003
    Posts
    11
    Originally posted by Prelude
    >If you want- I can include that
    Read my second paragraph for details of what you should do to get better help.

    >because they seem like they should work
    Why do you think so? temp is a pointer to wordnode yet temp->right and temp->left are pointers to element. It's not terribly surprising that you are having issues with assignment.

    ^look up, Hammer called me on that already, That was my problem.

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >That was my problem
    Yes, I know.

    >^look up, Hammer called me on that already
    Well, since you're final post said nothing about solving the problem and only mentioned Hammer's suggestion (duplicating mine) to use comments to mark your code, I assumed you still hadn't gotten your answer.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Double Linked List Problem
    By Shiggins in forum C++ Programming
    Replies: 4
    Last Post: 03-10-2009, 07:15 AM
  2. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM