Thread: linked list

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    3

    linked list

    I am trying to add a node. Does this seem right??
    Code:
    LNode*  AddItem(LNode  *headPtr, int  newItem)
    {
        auto struct LNode **nodePtr;
        for (nodePtr = &LNode; *nodePtr != NULL; nodePtr = &(*nodePtr) -> next)
            {
            auto struct LNode *lPtr = *nodePtr;
            if(newItem < lPtr ->value)
                {
                }
            }
        nodePtr = malloc(sizeof(LNode));
        if (NULL == nodePtr)
            {
            printf("Error allocating memeory ");
            }
        else
            {
            nodePtr -> value = newItem;
            nodePtr -> next = headPtr;
            return nodePtr;
            }
    }  // end of "AddItem"

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    C code again i would say, like your previous post? First finish with one function, i suggest this and then try to remove a node.See what ideas i gave you in your other post and try to take it step by step!

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    This is supposed to be C++ right? Afterall, you've used the auto keyword.

    Why are you using the struct keyword in there, and why is there a printf and a malloc call?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Declaring linked list inside linked list
    By blueboyz in forum C Programming
    Replies: 33
    Last Post: 04-20-2012, 10:13 AM
  2. Replies: 4
    Last Post: 05-01-2010, 10:19 PM
  3. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  4. singly linked list to doubly linked list
    By t48j in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 06:37 PM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM