programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Sort the Arrays!

Khurram Akhter
Greenhorn
Posts: 3
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
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:
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
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

kevin schmidt
Ranch Hand
Posts: 85
Another thing that you could do is this
Arrays.sort(nameOfArray);
kevin