Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- using System.IO;
- namespace Program1
- {
- class Program
- {
- public static void InsertSorting(int[] array)
- {
- int x; int j;
- for (int i = 0; i < array.Length; i++)
- {
- Thread.Sleep(1000);
- x = array[i];
- for (j = i - 1; j >= 0 && array[j] > x; j--)
- {
- array[j + 1] = array[j];
- }
- array[j + 1] = x;
- }
- }
- static void Main(string[] args)
- {
- ConsoleKeyInfo keyPressed;
- int arrangeLength;
- string path = @"d:/dat.bin";
- do
- {
- Console.WriteLine("Input length of your arrange");
- Console.Write("-->");
- arrangeLength = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Press Space to continue");
- keyPressed = Console.ReadKey();
- } while (keyPressed.Key != ConsoleKey.Spacebar);
- int[] arr = new int[arrangeLength];
- Random rnd = new Random();
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = rnd.Next(10, 100);
- }
- Byte[] byteArrange = new byte[arrangeLength];
- for (int i = 0; i < arr.Length; i++)
- {
- byteArrange[i] = Convert.ToByte(arr[i]);
- }
- InsertSorting(arr);
- if (path != null) {
- FileStream file = new FileStream(path, FileMode.Open, FileAccess.Write);
- file.Write(byteArrange, 0, byteArrange.Length);
- file.Close();
- }
- else
- {
- FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write);
- file.Write(byteArrange, 0, byteArrange.Length);
- file.Close();
- }
- var memoryStream = new MemoryStream(File.ReadAllBytes(path));
- Console.WriteLine("Sorting is done successfuly");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment