Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Problem

Status
Not open for further replies.

treds01

Programmer
Nov 26, 2002
2
GB
hi

I am tryign to find out if n/2 occurences of a digit appear in an array, the numbers will be next to each other, eg
A = [1,2,2,4,7,7,7,8,9]
IN this case it should return the 2 but not the 7 as is not n/2 cocurences.

Any ideas

Nick
 
>> IN this case it should return the 2 but not the 7 as is
>> not n/2 cocurences.

Shouldn't it return '1' also? Othewise I have no idea what you are saying.

-pete
 
Are you asking for a way to return a digit if it appears an even number of times consecutively(sp?) in an array?
----------------------------------------
There are no onions, only magic
----------------------------------------
 
sorry didn't explain very well, i am basically lookign for the majority element which is an element that apears more than n/2 times
 
jfryer, I think your onto something there :)

Sounds like a school assignment eh?

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top