Skip to content

Instantly share code, notes, and snippets.

@najikadri
Created April 25, 2015 14:47
Show Gist options
  • Save najikadri/145e8bd39885a4b58260 to your computer and use it in GitHub Desktop.
Save najikadri/145e8bd39885a4b58260 to your computer and use it in GitHub Desktop.
Statistics Sorter
import java.util.*;
//this class is used for statistics //incomplete version
public class Sorter {
public static ArrayList<Integer> reduce (ArrayList<Integer> init) {
ArrayList<Integer> newArray = new ArrayList<Integer>(100);
newArray.add(init.get(0));
for (int i: init) {
for (int x=0; x < newArray.size();x++) {
if (i != newArray.get(x) && x == (newArray.size()-1)){
if (!(isFound(i,newArray))) {
newArray.add(i);
}
}
}
}
return newArray;
}
public static boolean isFound (int i, ArrayList<Integer> a) {
boolean isFound = false;
for (int n: a ) {
if (n == i) {
isFound = true;
}
}
return isFound;
}
public static ArrayList<Integer> format (int[] v) {
ArrayList<Integer> newVal = new ArrayList<Integer>();
for (int i=0; i < v.length;i++) {
newVal.add(v[i]);
}
return newVal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment