Friday, April 25, 2008

Sorting two dimensional arrays in java

If you want to sort a data with its description, you may not use

Arrays.sort(data);

For example; to sort the following data according to values given by Bidders in ascending order;

"Bidder 1 = 25.2"

"Bidder 2 = 12.0"

"Bidder 3 = 45.0"

"Bidder 4 = 2.0"

and to get the result as;

"Bidder 3 = 45.0"

"Bidder 1 = 25.2"

"Bidder 2 = 12.0"

"Bidder 4 = 2.0"

to do this, we should create following temporary arrays.

bos_biddername [0] = "Bidder 1"; bos_deger [0] = 25.2;

bos_biddername [1] = "Bidder 2"; bos_deger [1] = 12.0;

bos_biddername [2] = "Bidder 3"; bos_deger[2] = 45.0;

bos_biddername [3] = "Bidder 4"; bos_deger [3] = 2.0


//sort manually bos_deger[] and get

// bos_biddername[] in descending order

double temp;
String temp2;

for (int ik = 0; ik < bos_deger.length - 1; ik++ ) {
for (int j = ik + 1; j < bos_deger.length; j++) {
if( bos_deger[ik] < bos_deger[j] ) //sorting
{ temp = bos_deger[ik]; //swapping
temp2 = bos_biddername[ik];
bos_deger[ik] = bos_deger[j];
bos_biddername[ik]=bos_biddername[j];
bos_deger[j] = temp;
bos_biddername[j] = temp2;
}
}
}
// end of sort




The result will be these sorted arrays in ascending order;

bos_biddername [0] = "Bidder 3"; bos_deger [0] = 45.0;
bos_biddername [1] = "Bidder 1"; bos_deger [1] = 25.2;
bos_biddername [2] = "Bidder 2"; bos_deger[2] = 12.0;
bos_biddername [3] = "Bidder 4"; bos_deger [3] = 2.0

Sunday, April 20, 2008















Designing a programme should look like a nice structure. This photo is taken yesterday in Ankara, Kecioren district. This is the new cable car (teleferic) building. This kind of pictures encourage me to be productive.
The camera that was used for this shot is Canon IXUS 850 IS.

Saturday, April 19, 2008

Creating a new webpage, working on programming, design and writing books what I would like to do...

To do this, takes time. I hope I wıll achieve them.