78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
class Program
|
|
{
|
|
static void Feladat1()
|
|
{
|
|
//egyszerű rendezés
|
|
int[] t = {22,-5,4,33,9,-3,7,15,0,20};
|
|
int n = t.Length;
|
|
for (int i = 0; i < n; ++i)
|
|
Console.WriteLine($"{t[i]}");
|
|
Console.WriteLine("");
|
|
|
|
for (int i = 0; i < n - 1; ++i)
|
|
{
|
|
for (int j = i + 1; j < n; ++j)
|
|
{
|
|
if (t[i] > t[j])
|
|
{
|
|
int swap = t[j];
|
|
t[j] = t[i];
|
|
t[i] = swap;
|
|
}
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("Rendezés után:");
|
|
for (int i = 0; i < n; ++i)
|
|
Console.WriteLine($"{t[i]}");
|
|
Console.WriteLine("");
|
|
|
|
|
|
}
|
|
|
|
static void Feladat2()
|
|
{
|
|
//buborékos rendezés
|
|
int[] t = { 22, -5, 4, 33, 9, -3, 7, 15, 0, 20 };
|
|
int n = t.Length;
|
|
for (int i = 0; i < n; ++i)
|
|
Console.WriteLine($"{t[i]}");
|
|
Console.WriteLine("");
|
|
|
|
for (int i = n - 1; i > 0; --i)
|
|
{
|
|
for (int j = 0; j < i; ++j)
|
|
{
|
|
if (t[j] > t[j+1])
|
|
{
|
|
int swap = t[j+1];
|
|
t[j+1] = t[j];
|
|
t[j] = swap;
|
|
}
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("Rendezés után:");
|
|
for (int i = 0; i < n; ++i)
|
|
Console.WriteLine($"{t[i]}");
|
|
Console.WriteLine("");
|
|
|
|
|
|
}
|
|
static void Main(string[] args)
|
|
{
|
|
Feladat1();
|
|
Feladat2();
|
|
Console.ReadKey();
|
|
}
|
|
}
|
|
}
|