hey... i cant paste whole code here. there is some limitation here. any way i will place some of it. all those are in java. don't worry. there are not much to modify.. these function may look lengthy but simplest for you . easy to understand. ok. no complex coding i have done. thinking you are a beginner .. all you have to change is "input.length " to length of the array, pass the length of array to the function. so change the function to public int[] *******Sort(int[] input, SortMode sortMode, int length)
// I use this enum to set the mode of sorting. my sort functions use this
enum SortMode
{
Ascending ,Descending
};
// this method is a must for my code.
private void swap(int[] input, int i , int j)
{
int temp ;
temp = input[i];
input[i]= input[j];
input[j]= temp;
}
// Insertion sort
public int[] InsertionSort(int[] input, SortMode sortMode)
{
if( sortMode == SortMode.Ascending)
{
for( int i = 1 ; i < input.length ; i++ )
{
for( int j = 0 ; j < i ; j++ )
{
if( input [j] > input [i] )
{
swap(input , i , j);
}
}
}
}
else
{
for( int i = 1 ; i < input.length ; i++ )
{
for( int j = 0 ; j < i ; j++ )
{
if( input [j] < input [i] )
{
swap(input , i , j);
}
}
}
}
return input;
}
// Selection Sort
public int[] SelectionSort(int[] input, SortMode sortMode)
{
if (sortMode == SortMode.Ascending)
{
for (int i = 0 ; i < input.length ; i++ )
{
for(int j = i+1 ; j < input.length ; j++ )
{
if( input [i] > input[j])
{
swap(input, i, j);
}
}
}
}
else
{
for (int i = 0 ; i < input.length ; i++ )
{
for(int j = i+1 ; j < input.length ; j++ )
{
if( input [i] < input[j])
{
swap(input, i, j);
}
}
}
}
return input;
}
for the rest .. if you can provide email id .. i can mail you.. ( don't worry .i am not a spammer. still you think i am, create a temporary email id and give me )