Thread: addition in linked lists

  1. #1
    Registered User
    Join Date
    Nov 2010

    Unhappy addition in linked lists

    How can i make addition in my linked lists if the nodes are stroing two values:
    1) int element
    2) int colomnvalue
    i have to make the addition on the basis that the nodes having the same colomvalue, thier element should be added.
    This addition is to be made in linked lists either by creating new linked lists or other way.. i am trying to make the logic but it stops on one or other way.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Create a function called initialiseNode, which takes your data values as parameters.
    It allocates the memory for a node, initialises all the pointers, and assigns the parameter values to the data portion of the node.

    You then pass this constructed node to one of your list insertion functions.

    If your list has both 'head' and 'tail' pointers, then it is very easy.

    To prepend to the start of the list, it's simply
    node->next = head;
    head = node;

    To append to the end of the list,
    tail->next = node;
    tail = node;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked Lists?!
    By hwing91 in forum C Programming
    Replies: 32
    Last Post: 11-08-2010, 06:13 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. Linked Lists Integer addition ? HELP Please??
    By green_eel in forum C Programming
    Replies: 3
    Last Post: 03-12-2003, 04:36 PM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 06:25 PM

Tags for this Thread