Here is the code:
public static void SortByLastName(ref string[] arrayOfLastNames, ref string[] arrayOfFirstNames, ref string[] arrayOfPlateNum, ref string[] arrayOfType, ref string[] arrayOfYear)
{
Console.Clear();
int vehicleCountInt = 0;
Console.WriteLine("SHOW DATABASE: SORTING BY LAST NAME\n");
using (StreamReader countVehicle = new StreamReader("vehiclecount.txt"))
{
vehicleCountInt = Int32.Parse(countVehicle.ReadLine());
}
using (StreamReader outputLastNames = new StreamReader("lastnames.txt"))
{
int[] b = new int[vehicleCountInt];
for (int i = 0; i < vehicleCountInt; i++)
{
arrayOfLastNames[i] = outputLastNames.ReadLine();
Console.WriteLine();
}
}
int N = arrayOfLastNames.Length;
int W = arrayOfLastNames[0].Length;
string[] temp = new string[vehicleCountInt];
for (int d = W - 1; d >= 0; d--)
{
int[] count = new int[vehicleCountInt];
for (int i = 0; i < N; i++)
{
count[arrayOfLastNames[i][d] + 1]++; //The part that causes the IndexOutOfRange exception
}
for (int k = 1; k < 256; k++)
{
count[k] += count[k - 1];
}
for (int i = 0; i < N; i++)
{
temp[count[arrayOfLastNames[i][d]]++] = arrayOfLastNames[i];
}
for (int i = 0; i < N; i++)
{
arrayOfLastNames[i] = temp[i];
Console.WriteLine("{0}", arrayOfLastNames[i]);
}
}
}
By the way this is one of the text file i'll be sorting:
Hibaler
Balde
Metin
Dela Vega
Dimagiba
Pederoso
Dinulos
Du
Gotengco
Lira
Guban
Garraez
Carpena
Reyes
Zulueta
Gonzalez
Isidoro
Marfa
Reyes
Guinhawa
Aaron
Lazaro
Obsum
Molino
Estenor
Nolasco
Paral
Porillo
Novillos
Alihan
This post has been edited by angelvale: 03 September 2009 - 03:54 AM

Start a new topic
Add Reply





MultiQuote
| 


