Hi i have c# code for to sort text file using quicksort algo, but the problem is that i can sort only upto 300MB , after that system get hang . i want to sort 1GB to 5GB text file. can anyone plz help me . here is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace quik
{
class Quicksort
{
public static void qsort(string[] items)
{
qs(items, 0, items.Length - 1);
}
static void qs(string[] items, int left, int right)
{
int i, j;
string x, y;
i = left; j = right;
x = items[(left + right) / 2];
do
{
while ( (items[i].CompareTo (x)<0) &&(i < right)) i++;
while ((x.CompareTo(items[j])<0) && (j > left)) j--;
if (i <= j)
{
y = items[i];
items[i] = items[j];
items[j] = y;
i++; j--;
}
} while (i <= j);
if (left < j) qs(items, left, j);
if (i < right) qs(items, i, right);
}
}
public class QS
{
public static void Main()
{
// char[] a = { 'v', 'i', 'r', 'e', 'n', 'd', 'r' ,'a'};
string[] a = System.IO.File.ReadAllLines(@"C:\\3.txt");
int i;
//for (i = 0; i < a.Length; i++)
// Console.Write(a[i]);
//Console.WriteLine();
Quicksort.qsort(a);
using (System.IO.StreamWriter abc = new System.IO.StreamWriter(@"C:\write11.txt"))
{
for ( i = 0; i < a.Length; i++)
{
abc.WriteLine("{0}", a[i]);
}
}
//for (i = 0; i < a.Length; i++)
// Console.Write(a[i]);
}
}
}