Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

actionscript algorithm

Name: Anonymous 2012-01-25 15:41

im trying to find the most occurring element in an array, but im trying to be clever about it instead of doing the long as sub-array method my class is doing currently

i cant tell why this isnt working

http://pastebin.com/u9Vad3Jf

any help would be appreciated

Name: Anonymous 2012-01-25 16:22

damn AS programmers are stupid. probably because they are descendent from java programmers, only much younger. here, convert it to your stupid language.

#include<stdio.h>

int cmp(const void * a, const void * b){
  return *(int*)a - *(int*)b;
}

int main(){
  int i, current, max, maxi;
  int arr[] = { 2, 3, 1, 3, 2, 1, 3};
  qsort (arr, 7, sizeof(int), cmp);
  current=max=maxi=0;
  for(i=1; i<7; i++){
    if(arr[i]==arr[i-1]) current++;
    else current=0;
    if(current>max){
      max=current;
      maxi=i;
    }
  }
  printf("%d", arr[maxi]);
  return 0;
}


something like a bucket sort would be a lot better if values are small enough

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List