dle
Padekit surikiuoti masva - Java - Affiliate.lt

Jump to content


Photo
- - - - -

Padekit surikiuoti masva


  • Please log in to reply
1 reply to this topic

#1 auxiukas

auxiukas

    Junior Member

  • Members
  • Pip
  • 4 posts

Posted 06 March 2008 - 09:42 AM

Sveiki, man reikia programuotojo su java kad padetu surusiuoti elementus nuo maziausio link didziausio is masyvo, naudojanr bobble metoda. Masyvo pvz. int [] a = {23,5,1,8,15,9}. Is anksto dekui. :)

#2 valdorf

valdorf

    Junior Member

  • Members
  • PipPip
  • 19 posts

Posted 15 June 2008 - 11:16 AM

for(int pass=0; pass < sizeofarray &&
!isSorted(array); pass++){
for(int t=0; t < sizeofarray; t++){
if(array[t] > array[t+1]){
hold=array[t];
array[t] = array[t+1];
array[t+1] = hold;
}
}
}

public static boolean isSorted(int [] array)
{
boolean isSorted = true;

for(int i=0; i<(array.length-1) && isSorted; i++)
isSorted = array[i] <= array[i+1];

return isSorted;
}

Galbût èia tai ko ieðkai?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users