Like Tree1Likes
  • 1 Post By std10093

linked list

This is a discussion on linked list within the C++ Programming forums, part of the General Programming Boards category; I am trying to add a node. Does this seem right?? Code: LNode* AddItem(LNode *headPtr, int newItem) { auto struct ...

  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!
    espnstar likes this.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    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, 05:37 PM
  5. Replies: 6
    Last Post: 03-02-2005, 01:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21