SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 6th, 2002, 05:34 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Calculating the statistical mode

how do i find the mode of a list?

by this i mean the value that appears the most in a particular list.

for example:
List (array): 1, 2, 3, 3, 3, 5, 5, 10
Mode : 3

or

List (array): 1, 2, 3, 3, 3, 5, 5, 5
Mode: 3 and 5

thank you.

Reply With Quote
  #2  
Old November 20th, 2002, 07:56 AM
Sulik Sulik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 10 Sulik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face


Perhaps you should create a list (i mean the data structure where every element has a pointer to the next element) which will contain two numbers - first is the value of an item in your original list, and second is the number of times you have encountered that value in your original list.

I hope my bad English and too complex phrase construction will not be a barrier between out developing minds %-[]


Reply With Quote
  #3  
Old November 20th, 2002, 08:01 AM
Sulik Sulik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 10 Sulik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
as for your example - you'll have 4 nodes in your generated list, with values
1 1
2 1
3 3
5 3
respectively (pointers included).

Reply With Quote
  #4  
Old November 21st, 2002, 11:11 PM
Optix Optix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 36 Optix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
!

I wrote a program that found the mean, median, mode and range =) here is the part where it finds the mode:

Code:
void mode(double* nums, unsigned int choice)
{
	unsigned int index;
	int count=0;
	int max =0;
	for(index=0; index<choice; index++)
	{
		if(nums[index]==nums[index+1])
			count++;
		else
		{
			if(count>max)
				max=count;
			count=0;
		}
	}
	count=0;
	for(index=0; index<choice; index++)
	{
		if(nums[index]==nums[index+1])
			count++;
		else
		{
			if(count==max)
				cout<<"Mode(s):\t" <<nums[index]<<"\n";
			count=0;
		}
	}
}


:] hope this helps

Reply With Quote
  #5  
Old November 22nd, 2002, 02:25 AM
Sulik Sulik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 10 Sulik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy nonono

It will return only the count of the longest sequence of identical numbers.
But as I understand, you need to return the VALUE which is the most frequently appears in the whole sequence.
e.g. for a sequence

1, 2, 3, 4, 2, 4, 4, 2

your function will return THE COUNT 2 (of a value 4)
but the modes are THE VALUES 2 and 4 (appear 3 times both)

Reply With Quote
  #6  
Old November 23rd, 2002, 10:40 PM
Optix Optix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 36 Optix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
i am not really sure what u are tryin to say

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Calculating the statistical mode


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway