Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- namespace selection_sort
- {
- class Program
- {
- static void Main(string[] args)
- {
- int m = 0, min;
- Stopwatch time = new Stopwatch();
- string[] findFiles = Directory.GetFiles(@"F:\ИТМО\Комбинаторные алгоритмы\Сортировка\F_Sort");
- for (int q = 0; q < Directory.GetFiles(@"F:\ИТМО\Комбинаторные алгоритмы\Сортировка\F_Sort").Length; q++)
- {
- if (Path.GetFileName(findFiles[q]).Length < 11)
- {
- StreamReader file = new StreamReader(findFiles[q]);
- int n = Convert.ToInt16(Path.GetFileName(findFiles[q]).Remove(Path.GetFileName(findFiles[q]).IndexOf('_')));
- string s = file.ReadToEnd();
- int[] mas = new int[n];
- string[] buf;
- buf = s.Split();
- int k = 0;
- for (int i = 0; i < buf.Length; i++)
- {
- if (buf[i] != "")
- {
- mas[k] = Convert.ToInt16(buf[i]);
- k++;
- }
- }
- time.Start();
- k = 0;
- for (int i = 0; i < (mas.Length - 1); i++)
- {
- m = i; min = mas[m];
- for (int j = i + 1; j < mas.Length; j++)
- {
- if (mas[j] < min)
- {
- min = mas[j];
- m = j;
- }
- }
- mas[m] = mas[i];
- mas[i] = min;
- }
- time.Stop();
- bool is_true = true;
- for (int i = 1; i < mas.Length - 1; i++)
- {
- if (mas[i] > mas[i - 1])
- { is_true = true; }
- }
- using (StreamWriter Print = new StreamWriter(findFiles[q] + "_result"))
- {
- for (int i = 0; i < mas.Length; i++)
- {
- Print.Write("{0,5}", mas[i]);
- }
- if (is_true == true)
- Print.WriteLine("Массив отсортирован!");
- else Print.WriteLine("Массив не отсортирован!");
- Print.WriteLine(time.ElapsedTicks);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement