473,466 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how do you find the mode of an array

3 New Member
Here's my nonworking code:

Expand|Select|Wrap|Line Numbers
  1. int count = 0;
  2.         int prevCount = 0;
  3.         int totalCount = 0;
  4.  
  5.         for (int i = 0; i <array.length; i++){
  6.             for (int j = i + 1; j < array.length; j++){
  7.                 if (array[i] == array[j]){
  8.                     count++;
  9.                     i++;
  10.                 }
  11.             }
  12.  
  13.             if (count >= prevCount){
  14.                 totalCount++;
  15.             }
  16.  
  17.             prevCount = count;
  18.  
  19.             count = 0;
  20.         }
  21.  
Feb 10 '08 #1
1 6486
Laharl
849 Recognized Expert Contributor
What issue are you having with the code? Does it come out too high? Too low? Errors?

For an easier way to find the mode, look into a HashMap , since they can't have duplicates.
Feb 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
6
by: Dimitris Mandalidis | last post by:
Hello all, Suppose we have the following struct : struct foo { int a; int b; char *c; } And :
3
by: Nadav | last post by:
Hi, I am writing a mixed mode application, I have a mixed mode Assembly manipulating a managed byte array, to access this array in unmanaged code I '__pin' the array, As I understand, pining an...
1
by: Sluggoman | last post by:
Hi all, Am floundering through a course in which C was not a pre-req, but the assignment is in C - If someone could point out where I am going way off the rails, I'd apprecciate it. Please be...
1
by: Sluggoman | last post by:
Cannot seem to wrap my head around this, could someone help me with the logic? I need to pull the value which occurs most frequently from array - am writing a mini program to get logic sorted out,...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
4
by: tzuchien.chiu | last post by:
I've searched this new group with the keyword: "kernel library array list". I am looking for an open source C++ class library for kernel mode programming, because the C++ standard library and...
2
by: k1ckthem1dget | last post by:
I dont know how to find the mode of an array. I am to do the following. (1) Given the following: · A list of 11 integers; 1,2,3,3,3,2,2,1,3,4,5 (2) The program should:
1
by: mmf.stavelot | last post by:
How to find out what type of the data procedure in MSSQL 2005 returns? Using inquiry about sample. Example: SELECT paramtypes FROM sysprocedures; Result:
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.