Thread: incrementing values in a linked list?

  1. #1
    Learner Axel's Avatar
    Join Date
    Aug 2005

    incrementing values in a linked list?

    how exactly do you increment a value in a linked list node?

    for example, if i had 2.20 in one element and 3.30 in the next how do i add these together?
    double number;
    temp->total += number;
    // when i attempt to print it:
    printf("%.2f", start->total);
    the first element's number is printed, not the total. I'm guessing because each node holds a "total" therefore a new one is being assigned to each one. I have a total value in my structure. How do i combine the total value?

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    you combine them by using a global total variable, or using a head node and setting it's "number" field to the total of all sub nodes.

  3. #3
    Join Date
    Oct 2005
    Hi ,

    You can use a simple for loop in which read the value of the each node in to a variable and add the next node value to the earlier read variable and continue upto to node u want to.

    Example format

    for(temp=start;temp->value == <check value>;temp=temp->next)
    printf("Fianl value - %d",x);
    Hope this is helpful to you...

    Incase of any other queries... plz revert.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  3. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM