public static void ExchangeSort(int[] array)
{
int pass, i, n= array.Length;
int tempt;
for(pass=0; pass
{
for( i= pass+1; i< n; i++)
{
if(array[i]
{
tempt=array[pass];
array[pass]=array[i];
array[i]=tempt;
}
}
}
}
When I replace the parameter int[] array with List
Johnny
CrishPosted Apr 20, 2011, 6:44 AM
{
int i, j, temp; //be sure that the temp variable is the same "type" as the array
for ( i = 0; i < num.length - 1; i ++ )
{
for ( j = i + 1; j < num.length; j ++ )
{
if( num[ i ] < num[ j ] ) //sorting into descending order
{
temp = num[ i ]; //swapping
num[ i ] = num[ j ];
num[ j ] = temp;
}
}
}
Ankit NandekarPosted Apr 20, 2011, 4:11 AM
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] a = {5,4,3,7,4,9};
List
l.AddRange(a);
Program.ExchangeSort(l);
}
public static void ExchangeSort(List
{
int pass, i, n = array.Count;
int tempt;
for (pass = 0; pass < n; pass++)
{
for (i = pass + 1; i
if (array[i] < array[pass])
{
tempt = array[pass];
array[pass] = array[i];
array[i] = tempt;
}
}
}
for (int j = 0; j < n; j++)
{
Console.WriteLine(array[j]);
}
Console.ReadLine();
}
}
Ankit NandekarPosted Apr 20, 2011, 3:54 AM