how can I sort a 2d array???
in
Programming Questions
•
1 year ago
never mind I find it out!!!!
yeaaaa buddy!!!!!!!!
code:
String examplearray[][] = new String[5][3];
examplearray[0][0] = "hey";
examplearray[0][1] = "1";
examplearray[0][2] = "8";
examplearray[1][0] = "blabla";
examplearray[1][1] = "5";
examplearray[1][2] = "122";
examplearray[2][0] = "meh";
examplearray[2][1] = "3";
examplearray[2][2] = "88";
examplearray[3][0] = "axax";
examplearray[3][1] = "9";
examplearray[3][2] = "88";
examplearray[4][0] = "ababa";
examplearray[4][1] = "9";
examplearray[4][2] = "88";
size(300, 300);
println(int(examplearray[0][0]));
println(int(examplearray[1][0]));
String alfa[]= new String[2];
String alfa2[] = new String[2];
String a[] = new String[examplearray[0].length];
String b[] = new String[examplearray[0].length];
int alfabetisch = 0;
while(alfabetisch<examplearray.length-1)
{
alfa[0]=examplearray[alfabetisch][0];
alfa[1]=examplearray[alfabetisch+1][0];
alfa2[0]=examplearray[alfabetisch][0];
alfa2[1]=examplearray[alfabetisch+1][0];
alfa =sort(alfa);
if (alfa[0] != alfa2[0]) {
a= examplearray[alfabetisch];
b= examplearray[alfabetisch+1];
examplearray[alfabetisch] = b;
examplearray[alfabetisch+1] = a;
alfabetisch=0;
}
else
{
alfabetisch++;
}
}
String x[] = new String[examplearray[0].length];
String z[] = new String[examplearray[0].length];
int checkrow;
for (int kolom=1; kolom<examplearray[0].length; kolom++) {
checkrow = 0;
while (checkrow<examplearray.length-1) {
if (int(examplearray[checkrow][kolom]) < int(examplearray[(checkrow+1)][kolom])) {
x = examplearray[checkrow];
z = examplearray[checkrow+1];
examplearray[checkrow]= z;
examplearray[checkrow+1]=x;
checkrow=0;
}
else
{
checkrow++;
}
}
}
for (int i = 0; i<examplearray.length; i++) {
for (int t=0; t<examplearray[i].length; t++) {
text(examplearray[i][t], 20+60*t, 20+20*i);
}
}
1