diff --git a/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/13101aa6-772e-4902-ba33-e2871dcce1ba.vsidx b/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/13101aa6-772e-4902-ba33-e2871dcce1ba.vsidx new file mode 100644 index 0000000..064d45b Binary files /dev/null and b/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/13101aa6-772e-4902-ba33-e2871dcce1ba.vsidx differ diff --git a/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/4066a62d-da33-4fbe-b1d2-2f551fb65594.vsidx b/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/4066a62d-da33-4fbe-b1d2-2f551fb65594.vsidx new file mode 100644 index 0000000..70aef67 Binary files /dev/null and b/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/4066a62d-da33-4fbe-b1d2-2f551fb65594.vsidx differ diff --git a/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/5ae421d8-c0d8-48d7-9e04-4e6b58df94b0.vsidx b/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/5ae421d8-c0d8-48d7-9e04-4e6b58df94b0.vsidx deleted file mode 100644 index c9e560a..0000000 Binary files a/20250115/ConsoleApp1/.vs/ConsoleApp1/FileContentIndex/5ae421d8-c0d8-48d7-9e04-4e6b58df94b0.vsidx and /dev/null differ diff --git a/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/.suo b/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/.suo index 73c40ed..35557e1 100644 Binary files a/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/.suo and b/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/.suo differ diff --git a/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.backup.json b/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.backup.json index 80c30ef..70b0187 100644 --- a/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.backup.json +++ b/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.backup.json @@ -1,9 +1,9 @@ { "Version": 1, - "WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\", + "WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\", "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}" } ], @@ -20,11 +20,11 @@ "$type": "Document", "DocumentIndex": 0, "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", - "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", - "ViewState": "AgIAAIcAAAAAAAAAAAAuwKIAAAAFAAAAAAAAAA==", + "ViewState": "AgIAAG8BAAAAAAAAAAAqwIMBAAAeAAAAAAAAAA==", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2025-01-15T11:04:49.38Z", "EditorCaption": "" diff --git a/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.json b/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.json index 9cf4be5..2f463cc 100644 --- a/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.json +++ b/20250115/ConsoleApp1/.vs/ConsoleApp1/v17/DocumentLayout.json @@ -1,9 +1,9 @@ { "Version": 1, - "WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\ProgaOra\\20250115\\ConsoleApp1\\", + "WorkspaceRootPath": "C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20250115\\ConsoleApp1\\", "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}" } ], @@ -20,11 +20,11 @@ "$type": "Document", "DocumentIndex": 0, "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", - "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", - "ViewState": "AgIAAJ4AAAAAAAAAAAAowLIAAAAMAAAAAAAAAA==", + "ViewState": "AgIAAIEBAAAAAAAAAAAqwIEBAAAqAAAAAAAAAA==", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2025-01-15T11:04:49.38Z", "EditorCaption": "" diff --git a/20250115/ConsoleApp1/ConsoleApp1/Program.cs b/20250115/ConsoleApp1/ConsoleApp1/Program.cs index 57af16c..9341440 100644 --- a/20250115/ConsoleApp1/ConsoleApp1/Program.cs +++ b/20250115/ConsoleApp1/ConsoleApp1/Program.cs @@ -16,7 +16,7 @@ namespace ConsoleApp1 public T Value { get; set; } } - public class SajatLancoltLista: IEnumerable + public class LancoltLista: IEnumerable { public ListaElem Start { get; private set; } public ListaElem End { get; private set; } @@ -116,11 +116,11 @@ namespace ConsoleApp1 } } - public class SajatVerem : IEnumerable + public class Verem : IEnumerable { private List _lista; - public SajatVerem() + public Verem() { _lista = new List(); } @@ -163,29 +163,161 @@ namespace ConsoleApp1 } } - public class BinarisFa + public class Csomopont { - public T Value; - public BinarisFa Right; - public BinarisFa Left; + public int Adat { get; set; } + public Csomopont Bal { get; set; } + 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 { + 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) { - var lancolt = new SajatLancoltLista(); + var lancolt = new LancoltLista(); lancolt.Add(1); lancolt.Add(2); @@ -205,7 +337,7 @@ namespace ConsoleApp1 Console.WriteLine(item); } - var verem = new SajatVerem(); + var verem = new Verem(); verem.Push(11); verem.Push(12); verem.Push(13); @@ -221,8 +353,46 @@ namespace ConsoleApp1 Console.WriteLine("Pop:"); Console.WriteLine(verem.Pop()); - BinarisFa binarisFa = new BinarisFa(20); - binarisFa.Right + BinarisFa binarisFa = new BinarisFa(); + 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(); diff --git a/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.exe b/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.exe index ef2dae1..6282590 100644 Binary files a/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.exe and b/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.exe differ diff --git a/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.pdb b/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.pdb index 3e9ece7..657e04e 100644 Binary files a/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.pdb and b/20250115/ConsoleApp1/ConsoleApp1/bin/Debug/ConsoleApp1.pdb differ diff --git a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.csproj.FileListAbsolute.txt b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.csproj.FileListAbsolute.txt index 18a8546..599107a 100644 --- a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.csproj.FileListAbsolute.txt +++ b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.csproj.FileListAbsolute.txt @@ -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.exe 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 diff --git a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.exe b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.exe index ef2dae1..6282590 100644 Binary files a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.exe and b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.exe differ diff --git a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.pdb b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.pdb index 3e9ece7..657e04e 100644 Binary files a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.pdb and b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/ConsoleApp1.pdb differ diff --git a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 94c747e..20196db 100644 Binary files a/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/20250115/ConsoleApp1/ConsoleApp1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ