Multimode//No mode?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Re: Multimode//No mode?

 
0
  #11
Apr 23rd, 2007
Originally Posted by Ancient Dragon View Post
>>However, if there is no mode (every number only appears once), it just returns the first number for mode. if there is more then one mode, it just returns the first mode.

What behavior do you want it to do ?

cout << "no mode" or "null" (doesnt really matter)

and if there is multiple modes, list them
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,468
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Multimode//No mode?

 
0
  #12
Apr 24th, 2007
what I would do is create another list of all the modes. The way you have it programmed it can print only one mode. Create a 2d array, the first dimension will have the actual value and the second dimension the number of times that value occurs in the original array. Something like this (untested)
  1. int array[2][length] = {0};
  2.  
  3. // populate array with values
  4. int nItemsInList = 1;
  5. array[0][0] = list[0];
  6. array[0][1] = 1;
  7. for(int i = 1; i < length; i++)
  8. {
  9. // find list[i] in array[0];
  10. int found = 0;
  11. for(int j = 0; j < nItemsInList; j++)
  12. {
  13. // search the array for list[i]. If found, then just increment
  14. // its count. If not found, then add it to the array.
  15. if( array[0][j] == list[i] )
  16. {
  17. array[1][j]++;
  18. found = 1;
  19. break;
  20. }
  21. }
  22. if( found == 0)
  23. {
  24. // not found in the array, so we must add it here.
  25. array[0][nItemsInList] = list[i];
  26. array[1][nItemsInList] = 1;
  27. nItemsInList++;
  28. }
  29. }

Now all that is left is to run through the array and find the items(s) with the largest quantity.
Last edited by Ancient Dragon; Apr 24th, 2007 at 12:08 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Re: Multimode//No mode?

 
0
  #13
Apr 24th, 2007
would i need to declare any more variables? sorry, i kind of need things spelled out for me. thanks for the insight, ill test it soon
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,468
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Multimode//No mode?

 
0
  #14
Apr 24th, 2007
see line 1
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Re: Multimode//No mode?

 
0
  #15
Apr 24th, 2007
thanks... still triyng
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC