aspose file tools*
The moose likes Beginning Java and the fly likes Sort the Arrays! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sort the Arrays!" Watch "Sort the Arrays!" New topic
Author

Sort the Arrays!

Khurram Akhter
Greenhorn

Joined: Oct 08, 2001
Posts: 3
I made an array
int []aa = { 1,5,2,6,7,9,8}
I want to sort this array with the help of for loop, so what
should i do now....
sandeep jakkaraju
Greenhorn

Joined: Sep 05, 2001
Posts: 8
You have to use ... Sorting algos ... like insert sort, merge ..etc
I am giving you the code for Insert Sort Ok !!
int temp ;
for( int j = 1; j<aa.length ; j++)>
{
for( int i = 0; i<j ; i++)>
{
temp = aa[i];
aa[i] = aa[j];
aa[j] = temp;
}
}

Originally posted by Khurram Akhter:
I made an array
int []aa = { 1,5,2,6,7,9,8}
I want to sort this array with the help of for loop, so what
should i do now....

M Iftikhar
Greenhorn

Joined: Oct 09, 2001
Posts: 3
There are two methods of sorting .
1 Bubble sorting
2 Internal sorting
Following is the procedure of internal sortting
int i=0,j=0,temp=0;
for(i=0 ; i < aa.length() ; i++){
for(j=i+1; j<=aa.length() ;j++){
if(aa[i] > aa[j]){
temp=aa[i];
aa[i] = aa[j];
aa[j] = temp;
}
}
}
Note :
Not sure aboout the method of aa.length() or aa.length



Iftikhar
kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Another thing that you could do is this
Arrays.sort(nameOfArray);
kevin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sort the Arrays!