added solution for Feladatok.pdf
This commit is contained in:
parent
7a859a9aaf
commit
9239fcb71d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"Version": 1,
|
"Version": 1,
|
||||||
"WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\",
|
"WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\",
|
||||||
"Documents": [
|
"Documents": [
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|c:\\users\\szabomarton\\desktop\\progaora\\20250115\\consoleapp1\\consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
"AbsoluteMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|c:\\users\\szabomarton\\desktop\\c#\\progaora\\20250115\\consoleapp1\\consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
"RelativeMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|solutionrelative:consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|solutionrelative:consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -20,11 +20,11 @@
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 0,
|
"DocumentIndex": 0,
|
||||||
"Title": "Program.cs",
|
"Title": "Program.cs",
|
||||||
"DocumentMoniker": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
"DocumentMoniker": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
||||||
"RelativeDocumentMoniker": "ConsoleApp1\\Program.cs",
|
"RelativeDocumentMoniker": "ConsoleApp1\\Program.cs",
|
||||||
"ToolTip": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
"ToolTip": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
||||||
"RelativeToolTip": "ConsoleApp1\\Program.cs",
|
"RelativeToolTip": "ConsoleApp1\\Program.cs",
|
||||||
"ViewState": "AgIAAIcAAAAAAAAAAAAuwKIAAAAFAAAAAAAAAA==",
|
"ViewState": "AgIAAG8BAAAAAAAAAAAqwIMBAAAeAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-01-15T11:04:49.38Z",
|
"WhenOpened": "2025-01-15T11:04:49.38Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"Version": 1,
|
"Version": 1,
|
||||||
"WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\",
|
"WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\",
|
||||||
"Documents": [
|
"Documents": [
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|c:\\users\\szabomarton\\desktop\\progaora\\20250115\\consoleapp1\\consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
"AbsoluteMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|c:\\users\\szabomarton\\desktop\\c#\\progaora\\20250115\\consoleapp1\\consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
"RelativeMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|solutionrelative:consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{1253C52B-9EE2-419E-8ACF-C9DB566348E9}|ConsoleApp1\\ConsoleApp1.csproj|solutionrelative:consoleapp1\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -20,11 +20,11 @@
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 0,
|
"DocumentIndex": 0,
|
||||||
"Title": "Program.cs",
|
"Title": "Program.cs",
|
||||||
"DocumentMoniker": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
"DocumentMoniker": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
||||||
"RelativeDocumentMoniker": "ConsoleApp1\\Program.cs",
|
"RelativeDocumentMoniker": "ConsoleApp1\\Program.cs",
|
||||||
"ToolTip": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
"ToolTip": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\ConsoleApp1\\Program.cs",
|
||||||
"RelativeToolTip": "ConsoleApp1\\Program.cs",
|
"RelativeToolTip": "ConsoleApp1\\Program.cs",
|
||||||
"ViewState": "AgIAAJ4AAAAAAAAAAAAowLIAAAAMAAAAAAAAAA==",
|
"ViewState": "AgIAAIEBAAAAAAAAAAAqwIEBAAAqAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-01-15T11:04:49.38Z",
|
"WhenOpened": "2025-01-15T11:04:49.38Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace ConsoleApp1
|
||||||
public T Value { get; set; }
|
public T Value { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SajatLancoltLista<T>: IEnumerable<T>
|
public class LancoltLista<T>: IEnumerable<T>
|
||||||
{
|
{
|
||||||
public ListaElem<T> Start { get; private set; }
|
public ListaElem<T> Start { get; private set; }
|
||||||
public ListaElem<T> End { get; private set; }
|
public ListaElem<T> End { get; private set; }
|
||||||
|
@ -116,11 +116,11 @@ namespace ConsoleApp1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SajatVerem<T> : IEnumerable<T>
|
public class Verem<T> : IEnumerable<T>
|
||||||
{
|
{
|
||||||
private List<T> _lista;
|
private List<T> _lista;
|
||||||
|
|
||||||
public SajatVerem()
|
public Verem()
|
||||||
{
|
{
|
||||||
_lista = new List<T>();
|
_lista = new List<T>();
|
||||||
}
|
}
|
||||||
|
@ -163,29 +163,161 @@ namespace ConsoleApp1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BinarisFa<T>
|
public class Csomopont
|
||||||
{
|
{
|
||||||
public T Value;
|
public int Adat { get; set; }
|
||||||
public BinarisFa<T> Right;
|
public Csomopont Bal { get; set; }
|
||||||
public BinarisFa<T> Left;
|
public Csomopont Jobb { get; set; }
|
||||||
|
|
||||||
public BinarisFa(T value)
|
public Csomopont(int adat)
|
||||||
{
|
{
|
||||||
Value = value;
|
this.Adat = adat;
|
||||||
|
this.Bal = null;
|
||||||
|
this.Jobb = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BinarisFa
|
||||||
|
{
|
||||||
|
public Csomopont Gyoker { get; private set; }
|
||||||
|
|
||||||
|
public void Add(int adat)
|
||||||
|
{
|
||||||
|
Gyoker = AddRekurziv(Gyoker, adat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(int value)
|
private Csomopont AddRekurziv(Csomopont csomopont, int adat)
|
||||||
{
|
{
|
||||||
|
if (csomopont == null)
|
||||||
|
{
|
||||||
|
return new Csomopont(adat);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (adat < csomopont.Adat)
|
||||||
|
{
|
||||||
|
csomopont.Bal = AddRekurziv(csomopont.Bal, adat);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (adat > csomopont.Adat)
|
||||||
|
{
|
||||||
|
csomopont.Jobb = AddRekurziv(csomopont.Jobb, adat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return csomopont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InorderBejaras()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Inorder bejárás:");
|
||||||
|
InorderRekurziv(Gyoker);
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InorderRekurziv(Csomopont csomopont)
|
||||||
|
{
|
||||||
|
if (csomopont == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InorderRekurziv(csomopont.Bal);
|
||||||
|
Console.WriteLine($"{csomopont.Adat}, ");
|
||||||
|
InorderRekurziv(csomopont.Jobb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
|
public static int BinarisKereses(int[] arr, int value)
|
||||||
|
{
|
||||||
|
int eleje = 0;
|
||||||
|
int vege = arr.Length - 1;
|
||||||
|
while (eleje <= vege)
|
||||||
|
{
|
||||||
|
int i = (eleje + vege) / 2;
|
||||||
|
if (arr[i] == value)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (arr[i] < value)
|
||||||
|
{
|
||||||
|
eleje = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (arr[i] > value) {
|
||||||
|
vege = i - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] Buborekrendezes(int[] arr)
|
||||||
|
{
|
||||||
|
for (int i = arr.Length - 1; i > 0; i--)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < i; j++)
|
||||||
|
{
|
||||||
|
if (arr[j] > arr[i])
|
||||||
|
{
|
||||||
|
int tmp = arr[j];
|
||||||
|
arr[j] = arr[i];
|
||||||
|
arr[i] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] BeszuroRendez(int[] arr) {
|
||||||
|
for (int i = 1; i < arr.Length; i++)
|
||||||
|
{
|
||||||
|
int j = i - 1;
|
||||||
|
var temp = arr[i];
|
||||||
|
while ((j >= 0) && arr[j] > temp)
|
||||||
|
{
|
||||||
|
arr[j + 1] = arr[j];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
arr[j + 1] = temp;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Gyorsrendez(int[] tomb, int eleje, int vege)
|
||||||
|
{
|
||||||
|
if (eleje < vege)
|
||||||
|
{
|
||||||
|
int kozepe = Feloszt(tomb, eleje, vege);
|
||||||
|
Gyorsrendez(tomb, eleje, kozepe - 1);
|
||||||
|
Gyorsrendez(tomb, kozepe + 1, vege);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Feloszt(int[] tomb, int eleje, int vege)
|
||||||
|
{
|
||||||
|
int kozepe = tomb[vege];
|
||||||
|
int kozepindex = eleje;
|
||||||
|
|
||||||
|
for (int i = eleje; i < vege; i++)
|
||||||
|
{
|
||||||
|
if (tomb[i] <= kozepe)
|
||||||
|
{
|
||||||
|
int temp = tomb[i];
|
||||||
|
tomb[i] = tomb[kozepindex];
|
||||||
|
tomb[kozepindex] = temp;
|
||||||
|
kozepindex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int kozepindexErteke = tomb[kozepindex];
|
||||||
|
tomb[kozepindex] = tomb[vege];
|
||||||
|
tomb[vege] = kozepindexErteke;
|
||||||
|
return kozepindex;
|
||||||
|
}
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var lancolt = new SajatLancoltLista<int>();
|
var lancolt = new LancoltLista<int>();
|
||||||
|
|
||||||
lancolt.Add(1);
|
lancolt.Add(1);
|
||||||
lancolt.Add(2);
|
lancolt.Add(2);
|
||||||
|
@ -205,7 +337,7 @@ namespace ConsoleApp1
|
||||||
Console.WriteLine(item);
|
Console.WriteLine(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
var verem = new SajatVerem<int>();
|
var verem = new Verem<int>();
|
||||||
verem.Push(11);
|
verem.Push(11);
|
||||||
verem.Push(12);
|
verem.Push(12);
|
||||||
verem.Push(13);
|
verem.Push(13);
|
||||||
|
@ -221,8 +353,46 @@ namespace ConsoleApp1
|
||||||
Console.WriteLine("Pop:");
|
Console.WriteLine("Pop:");
|
||||||
Console.WriteLine(verem.Pop());
|
Console.WriteLine(verem.Pop());
|
||||||
|
|
||||||
BinarisFa<int> binarisFa = new BinarisFa<int>(20);
|
BinarisFa binarisFa = new BinarisFa();
|
||||||
binarisFa.Right
|
binarisFa.Add(5);
|
||||||
|
binarisFa.Add(2);
|
||||||
|
binarisFa.Add(8);
|
||||||
|
binarisFa.Add(1);
|
||||||
|
binarisFa.Add(7);
|
||||||
|
|
||||||
|
binarisFa.InorderBejaras();
|
||||||
|
|
||||||
|
int[] tomb = { 1, 12, 5, 6, 7, 3, 4, 2, 10, 11, 9, 8 };
|
||||||
|
|
||||||
|
Console.WriteLine("Tömb: ");
|
||||||
|
foreach (var item in tomb)
|
||||||
|
{
|
||||||
|
Console.Write($"{item} ");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine($"a 4-es elem indexe: {BinarisKereses(tomb, 4)}");
|
||||||
|
|
||||||
|
Console.Write($"A tömb buborékrendezve:");
|
||||||
|
int[] bubi = Buborekrendezes(tomb);
|
||||||
|
foreach (var item in bubi)
|
||||||
|
{
|
||||||
|
Console.Write($"{item} ");
|
||||||
|
}
|
||||||
|
int[] beszuro = BeszuroRendez(tomb);
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Beszuro rendez: ");
|
||||||
|
foreach (var item in beszuro)
|
||||||
|
{
|
||||||
|
Console.Write($"{item} ");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
Console.WriteLine("Gyorsrendezés: ");
|
||||||
|
Gyorsrendez(tomb, 0, tomb.Length - 1);
|
||||||
|
foreach (var item in tomb)
|
||||||
|
{
|
||||||
|
Console.Write($"{item} ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -5,3 +5,10 @@ C:\Users\szabomarton\Desktop\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug
|
||||||
C:\Users\szabomarton\Desktop\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.csproj.CoreCompileInputs.cache
|
C:\Users\szabomarton\Desktop\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.csproj.CoreCompileInputs.cache
|
||||||
C:\Users\szabomarton\Desktop\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.exe
|
C:\Users\szabomarton\Desktop\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.exe
|
||||||
C:\Users\szabomarton\Desktop\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.pdb
|
C:\Users\szabomarton\Desktop\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.pdb
|
||||||
|
C:\Users\szabomarton\Desktop\C#\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.exe.config
|
||||||
|
C:\Users\szabomarton\Desktop\C#\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.exe
|
||||||
|
C:\Users\szabomarton\Desktop\C#\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.pdb
|
||||||
|
C:\Users\szabomarton\Desktop\C#\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.csproj.AssemblyReference.cache
|
||||||
|
C:\Users\szabomarton\Desktop\C#\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.csproj.CoreCompileInputs.cache
|
||||||
|
C:\Users\szabomarton\Desktop\C#\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.exe
|
||||||
|
C:\Users\szabomarton\Desktop\C#\ProgaOra\20250115\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.pdb
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user