Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Transactions;
- namespace _07_05
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[,] matrix = new[,]
- {
- { 5, 6, 1, 7, 7},
- {-1, 50, 8, 15, 3}
- };
- //Sort(matrix);
- Setrid(matrix);
- var rowLen = matrix.GetUpperBound(0) + 1;
- var colLen = matrix.GetUpperBound(1) + 1;
- var m = EnterInt("Enter n[2,20]: ", 2, 20);
- var n = EnterInt("Enter n[2,20]: ", 2, 10);
- var row = EnterInt($"Enter row[1,{rowLen}]: ", 1, rowLen) - 1;
- var position = EnterInt($"Enter position[1,{colLen}]: ", 1, colLen) - 1;
- Console.WriteLine($"Value is {matrix[row,position]}");
- var value = EnterInt("Enter new value: ");
- matrix[row, position] = value;
- Console.WriteLine($"New value is {matrix[row, position]}");
- }
- static void Setrid(int[,] array)
- {
- int rows = array.GetUpperBound(0) + 1;
- for (int row = 0; row < rows; row++)
- {
- int temp;
- for (int i = 0; i < array.Length / rows; i++)
- {
- for (int j = i + 1; j < array.Length / rows; j++)
- {
- if (array[row,i] < array[row, j])
- {
- temp = array[row, i];
- array[row, i] = array[row, j];
- array[row, j] = temp;
- }
- }
- }
- }
- }
- static int EnterInt(string text, int min = int.MinValue, int max = int.MaxValue)
- {
- int value;
- do
- Console.Write(text);
- while (!(int.TryParse(Console.ReadLine(), out value) &&
- value >= min &&
- value <= max));
- return value;
- }
- static int Partition<T>(T[,] m, int a, int b, int rows) where T : IComparable<T>
- {
- int rowLength = m.Length / rows;
- int i = a;
- for (int j = a; j <= b; j++)
- {
- if (m[j / rowLength, j % rowLength].CompareTo(m[b / rowLength, b % rowLength]) <= 0)
- {
- T t = m[i / rowLength, i % rowLength];
- m[i / rowLength, i % rowLength] = m[j / rowLength, j % rowLength];
- m[j / rowLength, j % rowLength] = t;
- i++;
- }
- }
- return i - 1;
- }
- public static void Sort<T>(T[,] m) where T : IComparable<T>
- {
- Sort(m, 0, m.Length - 1, m.GetUpperBound(0) + 1);
- }
- static void Sort<T>(T[,] m, int a, int b, int rows) where T : IComparable<T>
- {
- if (a >= b) return;
- int c = Partition(m, a, b, rows);
- Sort(m, a, c - 1, rows);
- Sort(m, c + 1, b, rows);
- }
- }
- }
Add Comment
Please, Sign In to add comment