diff --git a/.vs/prog2-ss2020-wienkop/DesignTimeBuild/.dtbcache.v2 b/.vs/prog2-ss2020-wienkop/DesignTimeBuild/.dtbcache.v2 index 0ef4edbe4b7c346cc961e0a5b30e0818eb3192fc..cf1f157a3454b0ec6f50ee005c98954c2c90c7df 100644 Binary files a/.vs/prog2-ss2020-wienkop/DesignTimeBuild/.dtbcache.v2 and b/.vs/prog2-ss2020-wienkop/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/prog2-ss2020-wienkop/v16/.suo b/.vs/prog2-ss2020-wienkop/v16/.suo index 289c2e892ab61cb2d5100675d1cb443d64372339..05b6b4f126299012e3d38730306a09458e0c9d55 100644 Binary files a/.vs/prog2-ss2020-wienkop/v16/.suo and b/.vs/prog2-ss2020-wienkop/v16/.suo differ diff --git a/02 UebgSa FiFoListe/Program.cs b/02 UebgSa FiFoListe/Program.cs index a7f746e81421a0eeca12f4c4c6c01ff87945db20..cecc24e6249427e5e253e6d0afc7bb91c36650ab 100644 --- a/02 UebgSa FiFoListe/Program.cs +++ b/02 UebgSa FiFoListe/Program.cs @@ -6,40 +6,91 @@ namespace _02_UebgSa_FiFoListe { class Element { - + public string name; + public Element next; + public Element(string name) { this.name = name; } + public override string ToString() => name; } Element anf, ende; int anz; public FiFoListe() { - + anf = ende = null; + anz = 0; } + /// <summary> + /// Fügt der Warteschlange ein neues Element hinzu + /// </summary> + /// <param name="text"></param> public void Push(string text) { - + Element neuesElement = new Element(text); + anz++; + if (anf == null) // Noch leere Liste? + anf = ende = neuesElement; + else + ende = ende.next = neuesElement; } - public void Push(params string[] texte) + /// <summary> + /// + /// </summary> + /// <param name="textFeld"></param> + public void Push(params string[] textFeld) { - + foreach (string text in textFeld) + Push(text); } - public string First() + /// <summary> + /// Liefert das erste Element zurück. Es bleibt aber in der Warteschlange + /// </summary> + /// <returns></returns> + public string First() { - + return (anf == null) ? null : anf.name; } - public string Pop() + /// <summary> + /// Liefert Wert des ersten Ausgabeelements zurück UND entfernt dieses aus der Warteschlange + /// </summary> + /// <returns></returns> + public string Pop() // { - + // 1.Fall: Liste ist leer + // 2.Fall: Liste besteht nur aus *einem* Element + // 3.Fall: Liste hat mehr als ein Element + if (anf == null) // 1. Fall + return null; + string erg = anf.name; // Ein return anf.name würde die Methode zu früh beenden!!! + anz--; + anf = anf.next; // 3. Fall + if (anf == null) // 2. Fall + ende = null; + return erg; } - public void WriteAll() + /// <summary> + /// Gibt alle Elemente der Warteschlange auf dem Bildschirm aus + /// </summary> + public void WriteAll() { - + for (Element tmp = anf; tmp != null; tmp = tmp.next) + Console.WriteLine(tmp); } + /// <summary> + /// liefert ein string-Feld mit allen gespeicherten Elementen zurück; + /// Elemente verbleiben in der Liste + /// </summary> + /// <returns></returns> public string[] GetAll() { - + string[] textFeld = new string[anz]; + int i = 0; + for (Element tmp = anf; tmp != null; tmp = tmp.next,i++) + textFeld[i] = tmp.name; + return textFeld; } - public int ItemCount { } - + /// <summary> + /// Anzahl der Elemente in der Warteschlange zurückgeben + /// </summary> + public int ItemCount { get => anz; } } class Program @@ -57,9 +108,10 @@ namespace _02_UebgSa_FiFoListe Console.WriteLine($"Pop: {f.Pop()}"); Console.WriteLine($"Anzahl der Elemente in der Liste: {f.ItemCount}"); Console.WriteLine("--------------"); - foreach (string item in f.GetAll()) + string[] namen = f.GetAll(); + foreach (string item in namen) { - Console.WriteLine(item); + Console.WriteLine($"foreach: {item}"); } } } diff --git a/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.deps.json b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.deps.json new file mode 100644 index 0000000000000000000000000000000000000000..104dd3e52a67ecc41d6cd10bd32ef5675577e02c --- /dev/null +++ b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v3.1", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v3.1": { + "02 UebgSa FiFoListe/1.0.0": { + "runtime": { + "02 UebgSa FiFoListe.dll": {} + } + } + } + }, + "libraries": { + "02 UebgSa FiFoListe/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.dll b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.dll new file mode 100644 index 0000000000000000000000000000000000000000..680d11fc0625bdafff6af2dd13e0c8388dfdaffd Binary files /dev/null and b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.dll differ diff --git a/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.exe b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.exe new file mode 100644 index 0000000000000000000000000000000000000000..c702a39802992fe1e125c9a1b3cf1b9dff6df767 Binary files /dev/null and b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.exe differ diff --git a/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.pdb b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.pdb new file mode 100644 index 0000000000000000000000000000000000000000..7cd1d3b4fccace40bfb70454d942a6baf2f5ec94 Binary files /dev/null and b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.pdb differ diff --git a/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.runtimeconfig.dev.json b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.runtimeconfig.dev.json new file mode 100644 index 0000000000000000000000000000000000000000..3becea41545888f98131d88ad51766e8ddde3bce --- /dev/null +++ b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.runtimeconfig.dev.json @@ -0,0 +1,8 @@ +{ + "runtimeOptions": { + "additionalProbingPaths": [ + "C:\\Users\\wienkop\\.dotnet\\store\\|arch|\\|tfm|", + "C:\\Users\\wienkop\\.nuget\\packages" + ] + } +} \ No newline at end of file diff --git a/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.runtimeconfig.json b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.runtimeconfig.json new file mode 100644 index 0000000000000000000000000000000000000000..bc456d7868bb54ec1809da30e339cd43f0a8a09c --- /dev/null +++ b/02 UebgSa FiFoListe/bin/Debug/netcoreapp3.1/02 UebgSa FiFoListe.runtimeconfig.json @@ -0,0 +1,9 @@ +{ + "runtimeOptions": { + "tfm": "netcoreapp3.1", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "3.1.0" + } + } +} \ No newline at end of file diff --git a/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csproj.CoreCompileInputs.cache b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000000000000000000000000000000000000..866b744e18d17bd43f4fc4b66cbb3dbc817b1992 --- /dev/null +++ b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +c0523642d3f3714f80c0cf31b3f8720f51a0bc09 diff --git a/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csproj.FileListAbsolute.txt b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csproj.FileListAbsolute.txt new file mode 100644 index 0000000000000000000000000000000000000000..40c08c12f0ea2649ed221c5469b2e27fa1591d1a --- /dev/null +++ b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csproj.FileListAbsolute.txt @@ -0,0 +1,13 @@ +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\obj\Debug\netcoreapp3.1\02 UebgSa FiFoListe.csprojAssemblyReference.cache +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\obj\Debug\netcoreapp3.1\02 UebgSa FiFoListe.csproj.CoreCompileInputs.cache +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\obj\Debug\netcoreapp3.1\02 UebgSa FiFoListe.AssemblyInfoInputs.cache +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\obj\Debug\netcoreapp3.1\02 UebgSa FiFoListe.AssemblyInfo.cs +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\bin\Debug\netcoreapp3.1\02 UebgSa FiFoListe.exe +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\bin\Debug\netcoreapp3.1\02 UebgSa FiFoListe.deps.json +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\bin\Debug\netcoreapp3.1\02 UebgSa FiFoListe.runtimeconfig.json +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\bin\Debug\netcoreapp3.1\02 UebgSa FiFoListe.runtimeconfig.dev.json +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\bin\Debug\netcoreapp3.1\02 UebgSa FiFoListe.dll +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\bin\Debug\netcoreapp3.1\02 UebgSa FiFoListe.pdb +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\obj\Debug\netcoreapp3.1\02 UebgSa FiFoListe.dll +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\obj\Debug\netcoreapp3.1\02 UebgSa FiFoListe.pdb +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgSa FiFoListe\obj\Debug\netcoreapp3.1\02 UebgSa FiFoListe.genruntimeconfig.cache diff --git a/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csprojAssemblyReference.cache b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csprojAssemblyReference.cache new file mode 100644 index 0000000000000000000000000000000000000000..74fe67b1ca671095970d4a7fbcae2417231e8f41 Binary files /dev/null and b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.csprojAssemblyReference.cache differ diff --git a/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.dll b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.dll new file mode 100644 index 0000000000000000000000000000000000000000..680d11fc0625bdafff6af2dd13e0c8388dfdaffd Binary files /dev/null and b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.dll differ diff --git a/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.exe b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.exe new file mode 100644 index 0000000000000000000000000000000000000000..c702a39802992fe1e125c9a1b3cf1b9dff6df767 Binary files /dev/null and b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.exe differ diff --git a/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.genruntimeconfig.cache b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.genruntimeconfig.cache new file mode 100644 index 0000000000000000000000000000000000000000..34bedab819ef1631d37d6e87ef9a716c545a105e --- /dev/null +++ b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.genruntimeconfig.cache @@ -0,0 +1 @@ +86c8e15dd33445635927cfaf398408205fd11473 diff --git a/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.pdb b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.pdb new file mode 100644 index 0000000000000000000000000000000000000000..7cd1d3b4fccace40bfb70454d942a6baf2f5ec94 Binary files /dev/null and b/02 UebgSa FiFoListe/obj/Debug/netcoreapp3.1/02 UebgSa FiFoListe.pdb differ diff --git a/02VerketteteListe-2/Program.cs b/02VerketteteListe-2/Program.cs index 9f67ed7194171c457d817383ac7acf9f3c6dba8d..859812659b4ff76b87d9bbc1538bd10ab2465688 100644 --- a/02VerketteteListe-2/Program.cs +++ b/02VerketteteListe-2/Program.cs @@ -1,8 +1,8 @@ using System; +using System.Collections; namespace _02VerketteteListe_2 -{ - +{ class StringListe { // Die Klasse Element ist nun eine *private* Klasse der Klasse StringListe @@ -11,51 +11,94 @@ namespace _02VerketteteListe_2 private class Element // Element ist eine private Hilfsklasse der Klasse StringListe { public string name; + public Element next = null; public Element(string name) { this.name = name; } - public Element next = null; // WAS IST NEXT??? public override string ToString() => name; } - Element anf, ende; + Element anf=null, ende=null; // int anz=0; - public StringListe() { anf = ende = null; } - public void AddEnd(string s) + //public StringListe() { } + public void AddEnd(string name) { - Element neuesElement = new Element(s); - if (anf == null) // Noch leere Liste? + Element neuesElement = new Element(name); // 1. Neues Element anlegen + if (anf == null) // 2. Leere Liste? anf = ende = neuesElement; else { - ende.next = neuesElement; + ende.next = neuesElement; // 3. Neues Element am Ende anfügen ende = ende.next; } } + public void AddFront(string name) + { + // 1. Leere Liste + // 2. Es existiert mind. ein Element + Element neuesElement = new Element(name); // Neues Element anlegen + if (anf == null) // 1.Fall: Leere Liste? + anf = ende = neuesElement; + else + { + neuesElement.next = anf; // 2. Fall + anf = neuesElement; + } + } public bool Suche(string name) { - for (Element tmp = anf; tmp != null; tmp = tmp.next) + for (Element item = anf; item != null; item = item.next) { - if (tmp.name == name) + if (item.name == name) return true; } return false; } public void Print() { - for (Element tmp = anf; tmp != null; tmp = tmp.next) + for (Element item = anf; item != null; item = item.next) { - Console.WriteLine(tmp); + Console.WriteLine(item); } } - public void LoescheAnf() + public IEnumerator GetEnumerator() + { + for (Element item = anf; item != null; item = item.next) + { + yield return item.name; // Merken dieser Ausführungsposition + // UND Zurückliefern von item.name + // Beim nächsten Aufruf von GetEnumerator() wird + // an der gespeicherten Pos. weitergemacht. + } + } + public void DeleteFront() { // 1.Fall: Liste ist leer // 2.Fall: Liste besteht nur aus einem Element // 3.Fall: Liste hat mehr als ein Element if (anf == null) // 1. Fall return; - anf = anf.next; // 3. Fall - if (anf == null) // 2. Fall - ende = null; + if (anf == ende) // 2. Fall + anf = ende = null; + else + anf = anf.next; // 3. Fall + } + public void DeleteEnd() + { + // 1.Fall: Liste ist leer + // 2.Fall: Liste besteht nur aus einem Element + // 3.Fall: Liste hat mehr als ein Element + if (anf == null) // 1. Fall + throw new NullReferenceException("Die Liste ist leer"); + if (anf == ende) // 2. Fall + anf = ende = null; + else // 3. Fall + { // Wir wissen: Die Liste hat mehr als ein Element, d.h. es gibt ein + // vorletztes Element vorletzter.next == ende + Element vorletzter = anf; + while (vorletzter.next != ende) + vorletzter = vorletzter.next; + vorletzter.next = null; + ende = vorletzter; + } } } class Program @@ -68,13 +111,26 @@ namespace _02VerketteteListe_2 //StringListe.Element e1 = new StringListe.Element("Anton"); //e1.next = null; - for (int i = 1; i <=5; i++) + for (int i = 1; i <=3; i++) { l1.AddEnd("Name-" + i); + } - l1.LoescheAnf(); + foreach (string item in l1) + { + Console.WriteLine($"foreach: {item}"); + } + //Console.WriteLine( l1.Print2()); + Console.WriteLine("=========="); + l1.DeleteEnd(); + l1.Print(); + Console.WriteLine("----------"); + l1.DeleteEnd(); l1.Print(); - Console.WriteLine($"Suche nach Name-3: {l1.Suche("Name-3")}"); + Console.WriteLine("----------"); + //l1.LoescheAnf(); + //l1.Print(); + //Console.WriteLine($"Suche nach Name-3: {l1.Suche("Name-3")}"); } } } diff --git a/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.dll b/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.dll index 101afa4797b70a4f4777e54b205c584629ae427f..15a2faee77b089a2afdc40f066ca5fa13b4c7892 100644 Binary files a/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.dll and b/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.dll differ diff --git a/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.pdb b/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.pdb index bf8e4ac55e5e3d7dba97450ec02c335dca6418e8..3baa29a36dd1896e1091a1554334687ea3d941b0 100644 Binary files a/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.pdb and b/02VerketteteListe-2/bin/Debug/netcoreapp3.1/02VerketteteListe-2.pdb differ diff --git a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csproj.FileListAbsolute.txt b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csproj.FileListAbsolute.txt index 6ec91f65eb59e5a4bf1e58828b2af8478ff5733b..e810c6ed60ba7f3b9cce543417891e39c74ffd0b 100644 --- a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csproj.FileListAbsolute.txt +++ b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csproj.FileListAbsolute.txt @@ -10,3 +10,4 @@ C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02VerketteteListe-2\obj\Debug C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02VerketteteListe-2\obj\Debug\netcoreapp3.1\02VerketteteListe-2.dll C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02VerketteteListe-2\obj\Debug\netcoreapp3.1\02VerketteteListe-2.pdb C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02VerketteteListe-2\obj\Debug\netcoreapp3.1\02VerketteteListe-2.genruntimeconfig.cache +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02VerketteteListe-2\obj\Debug\netcoreapp3.1\02VerketteteListe-2.csprojAssemblyReference.cache diff --git a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csprojAssemblyReference.cache b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csprojAssemblyReference.cache index 8a5ef041ae8402be96bf3fc66b33aedfc9a2f5c5..a0fbfd12797557adefa2aaaacd9d5126dec64303 100644 Binary files a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csprojAssemblyReference.cache and b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.csprojAssemblyReference.cache differ diff --git a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.dll b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.dll index 101afa4797b70a4f4777e54b205c584629ae427f..15a2faee77b089a2afdc40f066ca5fa13b4c7892 100644 Binary files a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.dll and b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.dll differ diff --git a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.pdb b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.pdb index bf8e4ac55e5e3d7dba97450ec02c335dca6418e8..3baa29a36dd1896e1091a1554334687ea3d941b0 100644 Binary files a/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.pdb and b/02VerketteteListe-2/obj/Debug/netcoreapp3.1/02VerketteteListe-2.pdb differ