diff --git a/OOP2024_AMP.sln b/OOP2024_AMP.sln index 88300807acc1a8302819d45f59adc365d7f228a9..9008f551ca0ffe8c66b2bad3884a8cff21e1c0b5 100644 --- a/OOP2024_AMP.sln +++ b/OOP2024_AMP.sln @@ -31,7 +31,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P13 Generics", "P13 Generic EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P11Mi Vererbung", "P11Mi Vererbung\P11Mi Vererbung.csproj", "{8F6110B2-04CA-444C-86AD-BC600B520F12}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P14 GenericList", "P14 GenericList\P14 GenericList.csproj", "{4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P14 GenericList", "P14 GenericList\P14 GenericList.csproj", "{4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P15 GenericSort", "P15 GenericSort\P15 GenericSort.csproj", "{35FAC883-FC17-4B7B-BA86-93B91B3C9803}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P16 GenericKeyValueList", "P16 GenericKeyValueList\P16 GenericKeyValueList.csproj", "{43F7D344-EBBF-4672-9452-AE59A1C977BF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -99,6 +103,14 @@ Global {4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}.Debug|Any CPU.Build.0 = Debug|Any CPU {4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}.Release|Any CPU.Build.0 = Release|Any CPU + {35FAC883-FC17-4B7B-BA86-93B91B3C9803}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35FAC883-FC17-4B7B-BA86-93B91B3C9803}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35FAC883-FC17-4B7B-BA86-93B91B3C9803}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35FAC883-FC17-4B7B-BA86-93B91B3C9803}.Release|Any CPU.Build.0 = Release|Any CPU + {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/P14 GenericList/DblList.cs b/P14 GenericList/DblList.cs index 4cdd984b1b7a209445bed462a686dd4594a99c61..9a4a56ae125a72c3648b3fbb9a533acc7ac21561 100644 --- a/P14 GenericList/DblList.cs +++ b/P14 GenericList/DblList.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace P14_GenericList { - class DblList<T>:IComparable<DblList<T>> - where T:IComparable<T> + class DblList<T> :IComparable<DblList<T>> + where T:IComparable<T> { class LItem { diff --git a/P14 GenericList/Person.cs b/P14 GenericList/Person.cs index 823678aecf1ef5c4ed09703268ec35b0536a5f8f..3742fcf6aff7ec689fe5c2b0509548490b9055ed 100644 --- a/P14 GenericList/Person.cs +++ b/P14 GenericList/Person.cs @@ -17,7 +17,7 @@ namespace P14_GenericList Alter = alter; } - public int CompareTo(Person other) => Name.CompareTo(other.Name); - //public int CompareTo(Person other) => Alter - other.Alter; + public int CompareTo(Person other) => this.Name.CompareTo(other.Name); + //public int CompareTo(Person other) => this.Alter - other.Alter; } } diff --git a/P14 GenericList/Program.cs b/P14 GenericList/Program.cs index 15b945df23de53f3329983dab1f0b6580986b54d..32a1328b183f2393295a1f0f5c5a8a3b64e9b2e3 100644 --- a/P14 GenericList/Program.cs +++ b/P14 GenericList/Program.cs @@ -23,16 +23,19 @@ { Console.WriteLine(item); } - DblList<DblList<Person>> pll = new(); + DblList<DblList<Person>> pll = new DblList<DblList<Person>>(); + DblList<Person> pl2 = new DblList<Person>(); pl2.AddSorted(new Person("Xaver", 63)); pl2.AddSorted(new Person("Zacharias", 69)); pll.AddSorted(pl); pll.AddSorted(pl2); - foreach (var item in pll) + foreach (var liste in pll) { - Console.WriteLine(item); + foreach (var item in liste) + Console.WriteLine(item); + Console.WriteLine("~~~~~~~~"); } } } diff --git a/P15 GenericSort/P15 GenericSort.csproj b/P15 GenericSort/P15 GenericSort.csproj new file mode 100644 index 0000000000000000000000000000000000000000..b8fa30e1dbbdb11eb7c9e4189468f73ee6edfd6e --- /dev/null +++ b/P15 GenericSort/P15 GenericSort.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <RootNamespace>P15_GenericSort</RootNamespace> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/P15 GenericSort/Program.cs b/P15 GenericSort/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..4f906088d437189a2079a5afe57389d8f5ad01a0 --- /dev/null +++ b/P15 GenericSort/Program.cs @@ -0,0 +1,15 @@ +namespace P15_GenericSort +{ + internal class Program + { + static void Sort<T>(T[] array) where T : IComparable<T> + { + if (array[i].CompareTo(array[j])<0) + Console.WriteLine("...."); + } + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/P16 GenericKeyValueList/KeyValueList.cs b/P16 GenericKeyValueList/KeyValueList.cs new file mode 100644 index 0000000000000000000000000000000000000000..a4636993a598110820f4a010b53186bca1e955bc --- /dev/null +++ b/P16 GenericKeyValueList/KeyValueList.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace P16_GenericKeyValueList +{ + class KeyValueList<K,V> where K: IComparable<K> + // where ~ Einschränkung an zulässigen Typ; hier von K + // class : IComparable ~ Die Klasse verpflichtet sich, IComparable zu impl. + { + class LItem + { + public K Key; + public V Value; + public LItem next = null; + public LItem(K Key, V Value) + { + this.Key = Key; + this.Value = Value; + } + } + LItem first = null, last = null; + private void Add(K key, V value) + { + LItem neu = new LItem(key,value); + if (first != null) + last = last.next = neu; + else + first = last = neu; + } + private LItem Find(K key) + { + for (LItem item = first; item != null; item = item.next) + { + if (item.Key.CompareTo(key)==0) + return item; + } + return null; + } + public V? this[K key] + { + get + { + LItem item = Find (key); + return (item == null) ? default : item.Value; + } + set + { + LItem item = Find (key); + if (item != null) + item.Value = value; + else + Add(key, value); + } + } + public IEnumerator<(K, V)> GetEnumerator() + { + for (LItem item = first; item != null; item = item.next) + yield return (item.Key, item.Value); + } + } +} diff --git a/P16 GenericKeyValueList/P16 GenericKeyValueList.csproj b/P16 GenericKeyValueList/P16 GenericKeyValueList.csproj new file mode 100644 index 0000000000000000000000000000000000000000..3e0596aae3e2b2c57cf955bbe9db7b62e3b7e807 --- /dev/null +++ b/P16 GenericKeyValueList/P16 GenericKeyValueList.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <RootNamespace>P16_GenericKeyValueList</RootNamespace> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/P16 GenericKeyValueList/Program.cs b/P16 GenericKeyValueList/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..f51068a9f221c4bb027ff927e6d0514a7758f465 --- /dev/null +++ b/P16 GenericKeyValueList/Program.cs @@ -0,0 +1,18 @@ +namespace P16_GenericKeyValueList +{ + internal class Program + { + static void Main(string[] args) + { + KeyValueList<string,int> tel = new KeyValueList<string, int>(); + tel["Wienkop"] = 1614; + tel["Otsa"] = 1855; + tel["Präsident"] = 4266; + + //Console.WriteLine( $"Präsident-Tel: {tel["Präsident"]}"); + foreach (var item in tel) { + Console.WriteLine( $"{item.Item1}: {item.Item2}"); + } + } + } +}