i think you are right..
so what you mean is that the display function is miss coded right?
i dont know where should i correct it in order to get the output as wat i mention above...
i think you are right..
so what you mean is that the display function is miss coded right?
i dont know where should i correct it in order to get the output as wat i mention above...
anyone please help ....i really need to finsih this up now... h help
id rather communicate here because: its permanent (or almost!), its public (so others can help and learn), and you can post your full code here with code tags for nice formatting.
i dont think anythings wrong with your display function. please reread my previous response to see if it makes any other sense to you... i think you just need ONE node PER ip address. if you have a duplicate ip address, then increase that node's count variable.
i dont see why you want to have duplicated nodes. (note: i said duplicated NODES not IP addresses)
back in the morning! good luck
this list will contain duplicate address. it cannot be change cause is a part of work....Originally Posted by nadroj
ok here is the explanation of overall work ...
<this program reads these IP addresses from a file and stores them in a linked list where each node will store the addresses and the number of times that address appears in the data file. list will be ordered in ascending order by IP address...As each address is read the program showuld check if it is already in the list. if it is then its count should be incremented by 1. if it isnt alreadyy int the list . should be inserted into the list so as to maintain the ordering of the list.
the display will look like
Please look at the list display
i still think from this description it is not requiring duplicate NODES. your not realizing that a NODE DOES NOT EQUAL IP ADDRESS.
PLEASE read this. i will repeat it from a previous post, this is how your looking at how the output should be:
Input File
--------------------------
192.149.089.061
100.001.004.031
034.056.078.012
192.149.089.061
100.001.004.031
192.149.089.061
111.022.033.004
192.149.089.061
111.022.033.004
111.022.033.004
IpAddress Count
--------------------------
192.149.089.061 4
192.149.089.061 4
192.149.089.061 4
192.149.089.061 4
100.001.004.031 2
100.001.004.031 2
034.056.078.012 1
111.022.033.004 3
111.022.033.004 3
111.022.033.004 3
this IS how it would look if you had duplicate NODES. you dont want duplicate nodes, you want duplicate IP ADDRESSES. a duplicate ip address is simply a node whose ip address has appeared 1+ times (which is stored in it's count variable).
this is how the output would appear if you dont have duplicate nodes (note you still have duplicate ip addresses):
Input File
--------------------------
192.149.089.061
100.001.004.031
034.056.078.012
192.149.089.061
100.001.004.031
192.149.089.061
111.022.033.004
192.149.089.061
111.022.033.004
111.022.033.004
IpAddress Count
--------------------------
192.149.089.061 4
100.001.004.031 2
034.056.078.012 1
111.022.033.004 3
are we on the same page yet?
You state in the preconditions to that function that a node with that address has to exist, so why do you create a new one ?.
If you really want to create a new node then you would have to remove the old one from the list and replace it with the new one.
Kurt
hi Zuk, well is not has to exist.... is <if exist, increment the count .....>
I'm not talking about the overall logic. I'm talking about the precondition to the function updateCount().
If exitance of the address is a precondition then updateCount() must not be called if the address doesn't exist. So according to the stated predcondition updateCount() has to find the node containing that address and simply increment its count member. No need to create a new node.
BTW: the way your function works now you would create a memory leak because you don't free the old node and you don't link the new node into the list.
Kurt
I was thinking about something like this
KurtCode:void IPlist::updateCount(string address ) // precondition : address is in list // postcondition : the count of node with address has been incremented { // no checks for 0 necessary, we know that it must be somewhere node *tmp = list; while( tmp->IPaddress != address) tmp = tmp->link; tmp->count++; }
thnx, the code is fine.. but the output is like this
IP address count
034.056.078.012 3998072
100.001.004.031 3998073
111.022.033.004 3998074
192.149.089.061 3998100
which is not right .. DAMN... :'(
i was thinking the same too but that isnt work for me as well ...
Last edited by peter_hii; 10-27-2006 at 09:06 AM.
How do you create new nodes ? Looks like count is not initialized to 1 when a new node is created.
Kurt
where should i initialize count to 0 ???in the private of the class??
I think that the main code has a logical error also - else is missing see my comment inside your code
Code:while(myFile>> filename) { if(ip.empty()) // store IP address into link list { ip.insertInOrder(filename); } //else is missing //because we inserted the new node IP address is already present //we will update the count for the first node - it is wrong if (!ip.isPresent(filename)) // if no duplicate ip address { ip.insertInOrder(filename); // we insert the ip address into link list } else { ip.updateCount(filename); // otherwise we add one to the count } } ip.display();
in the fuction insertInOrder you probably create new node.where should i initialize count to 0 ???in the private of the class??
you should initialize all its members, including count
Logically - at the beggining count should be set to 1 because it is the first occurence of this ip
so wat you mean isOriginally Posted by vart
initialize list in the insertinorder???