addition in linked lists

This is a discussion on addition in linked lists within the C++ Programming forums, part of the General Programming Boards category; How can i make addition in my linked lists if the nodes are stroing two values: 1) int element 2) ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    5

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,488
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 05: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, 03: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


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