count how many time the value appear in the link list -- HELP

This is a discussion on count how many time the value appear in the link list -- HELP within the C++ Programming forums, part of the General Programming Boards category; do you mean in the default constructor??...

  1. #31
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    do you mean in the default constructor??

  2. #32
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    I mean count should be set to 1 not 0 at the beggining - this will fix your output to
    IP address count
    034.056.078.012 1
    100.001.004.031 2
    111.022.033.004 3
    192.149.089.061 5

    I suppose the 192.149.089.061 was the first ip entered.
    look at my comment about missing else - this will fix 5 to 4

    do you mean in the default constructor??
    I mean here:
    Code:
    void IPlist::insertInOrder(string address)
    // precondition : list is ordered and address is not in list
    // postcondition : list is ordered and contains address
    {
        node *tmp = new node;
        tmp->IPaddress = address;
        tmp->count=1;...
    Last edited by vart; 10-27-2006 at 09:53 AM.

  3. #33
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Quote Originally Posted by vart
    I mean count should be set to 1 not 0 at the beggining - this will fix your output to
    IP address count
    034.056.078.012 1
    100.001.004.031 2
    111.022.033.004 3
    192.149.089.061 5

    I suppose the 192.149.089.061 was the first ip entered.
    look at my comment about missing else - this will fix 5 to 4
    yes the overall output is correct but the last ip address suppose to be 4//...
    i mean count 4 instead of 5

  4. #34
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    wat do you mean by this vart
    I suppose the 192.149.089.061 was the first ip entered.
    look at my comment about missing else - this will fix 5 to 4

  5. #35
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    read my comment #28 in this thread

  6. #36
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    >>yes the overall output is correct but the last ip address suppose to be 4//...
    i mean count 4 instead of 5

    This type of problem frequently occurs because of the wrong condition used in a loop to read in the file. If you have something like this:

    while(! ifstreamName.eof())

    instead of something like

    while (ifstreamName >> variableName)

    or this

    while(ifstreamName.getline())

    then you get the innappropriate result because the last item from the file can behave as if it were being read in twice. Posting the code that uses a loop to read the file would be helpful if this post doesn't help you check it on your own.
    You're only born perfect.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  3. Undefined Structure in Link List
    By _Cl0wn_ in forum C Programming
    Replies: 1
    Last Post: 03-22-2003, 04:57 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 04:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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