danya писал(а):
Comma писал(а):
Если тема актуально могу скинуть код, написанный мной корявым почерком на C# ))
ну я незнаю есть ли там такие методы
посути нельзя отсортировать не загружая
но помоему всякие методы пирамидальной сортировки и т.д. могут помочь с сортировкой большого объёма данных
да и ктомуже для огромных объёмов инфы базы данных придумали не?:)
а код сюда выкладывай на позыреть)
поэтому я и не вижу смысла записывать в файл, потом загрузить с него и , отсортировав кинуть оббратно в файл ))
БД то придумали, но меня обучить использовать БД они (те кто придумал) забыли
С# VS 2003 )))
Код:
using System;
using System.Text;
using System.IO;
using System.Collections.Specialized;
namespace TextReader
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
//public const int BubMthd = 0;
// another methods if exist
[STAThread]
static void IncreaseArrLength(ref string[] arr, int delta)
// increase the length of dynamic array if its need to add new elements to this array
// delta is an increment of the length of the given array
{
string[] tmp;
if (arr != null)
{
tmp = new string[arr.Length + delta];
Array.Copy(arr, 0, tmp, 0, arr.Length);
}
else
{
tmp = new string[delta];
int inLrn = tmp.Length;
}
arr = tmp;
}
static void Swap(int FElem, int SecElem, ref string [] arr)
// change places of two adjacent elements
{
string tmp;
tmp = arr[FElem];
arr[FElem] = arr[SecElem];
arr[SecElem] = tmp;
}
static void BubbleSort(ref string [] arr)
// methof of sort called as Bubble sort
{
int i, j;
int max = arr.Length;
for (i = 1; i < max; ++i)
for (j = 0; j < max - i; ++j)
if (arr[j].CompareTo( arr[j + 1] ) > 0) // if j is bigger
{
Swap(j, j + 1, ref arr); // then j+1 is emerge
}
}
static void SortStringVector (ref string [] arr, int SortID)
{
// /*
switch (SortID)
{
case 0 : BubbleSort(ref arr);
break;
default : Console.WriteLine("It is impossible to get here");
break;
}
// */
}
static void CheckInVectorOrNot (string [] arr, string CurStr, ref bool exist)
{
int i;
exist = false;
for (i=0; i<arr.Length; i++)
{
if (arr[i]==CurStr)
{
exist = true;
break;
}
}
}
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
string FullPath;
string st;
int LineCount = 0;
string [] lines = new string [0]; //= File
string ForExit;
bool WasAddedToVector = false;
//LineCount = 0;
Cycle :
{
Console.WriteLine ("Please, enter path to text file");
FullPath = Console.ReadLine();
//FullPath = A1;
if (File.Exists(FullPath))
{
//StreamReader sr = File.OpenText(FullPath); //, Encoding.UTF8);
StreamReader sr = new System.IO.StreamReader(@FullPath,Encoding.GetEncoding("windows-1251"));
while ((st=sr.ReadLine())!=null)
{
//Console.WriteLine(st);
if (LineCount!=0)
{
CheckInVectorOrNot(lines,st,ref WasAddedToVector);
}
else
{
WasAddedToVector = false;
}
if (WasAddedToVector!=true)
{
IncreaseArrLength(ref lines,1);
lines[LineCount] = st;
LineCount++;
}
}
sr.Close();
}
else
{
Console.WriteLine("File not found!!");
}
//Console.ReadLine();
}
SortStringVector(ref lines , 0);
Console.WriteLine("For Exit enter 'E' else other word to Continue");
ForExit = Console.ReadLine();
//lines.
if ( (ForExit)==("E") || (ForExit)==("e"))
{
Console.WriteLine("Enter path to save text file");
FullPath = Console.ReadLine(); //A2; //
StreamWriter sw = new StreamWriter(@FullPath, false);
foreach (string line in lines)
{
if (line.CompareTo("")!=0)
{
sw.WriteLine(line);
//sw.asdf;
}
}
sw.Close();
FullPath = null;
//FullPath = "";
st = null;
ForExit = null;
lines = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
//using (System.IO.File.WriteAllLines(FullPath, lines));
Console.WriteLine("Succesfully saved");
Console.ReadLine();
}
else
{
goto Cycle;
}
}
}
}
я тестил только на txt файлах где одно слово (или словосочетание) на отдельной строке расположено + размеры файлов маленькие были у мну