Advertisement
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;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void attoltes(ref int[,] tomb, ref List<int> lista, ref bool beki)
- {
- int k = 0;
- for (int j = 0; j < tomb.GetLength(0); j++)
- {
- for (int i = 0; i < tomb.GetLength(1); i++)
- {
- if (beki == true)
- {
- lista.Add(tomb[j, i]);
- }
- else
- {
- tomb[j, i] = lista[k++];
- }
- }
- }
- }
- static void rendezes(ref int[,] tomb)
- {
- List<int> lista = new List<int>();
- bool beki = true;
- attoltes(ref tomb, ref lista, ref beki);
- lista.Sort();
- beki = false;
- attoltes(ref tomb, ref lista, ref beki);
- }
- static void tombfeltolt(ref int[,] tomb, Random vel, ref int tombhatar1, ref int tombhatar2)
- {
- int generalt = 0;
- bool talal = false;
- int i;
- generalt = vel.Next(tombhatar1, tombhatar2+1);
- tomb[0, 0] = generalt;
- for (int j = 0; j < tomb.GetLength(0); j++)
- {
- if (j == 0)
- {
- i = 1;
- }
- else
- {
- i = 0;
- }
- for (; i < tomb.GetLength(1); i++)
- {
- do
- {
- talal = false;
- generalt = vel.Next(tombhatar1, tombhatar2 + 1);
- for (int k = 0; k < tomb.GetLength(0); k++)
- {
- for (int l = 0; l < tomb.GetLength(1); l++)
- {
- if (generalt == tomb[k, l])
- {
- talal = true;
- break;
- }
- }
- }
- } while (talal);
- tomb[j, i] = generalt;
- }
- }
- }
- static void kiirat(ref int[,] tomb)
- {
- for (int j = 0; j < tomb.GetLength(0); j++)
- {
- for (int i = 0; i < tomb.GetLength(1); i++)
- {
- Console.Write("{0, 4} ", tomb[j, i]);
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- uint sorszam, oszlopszam;
- Console.Write("Adja meg a sorok számát: ");
- sorszam = Convert.ToUInt32(Console.ReadLine());
- Console.Write("Adja meg az oszlopok számát: ");
- oszlopszam = Convert.ToUInt32(Console.ReadLine());
- int[,] tomb = new int[sorszam, oszlopszam];
- Console.WriteLine();
- int tombhatar1 = 1, tombhatar2 = 600;
- Random vel = new Random();
- tombfeltolt(ref tomb, vel, ref tombhatar1, ref tombhatar2);
- kiirat(ref tomb);
- rendezes(ref tomb);
- Console.WriteLine();
- kiirat(ref tomb);
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement