Commit f6e8d337 authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

2020-06-02 Di

parent 59872e26
using System;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -17,7 +18,44 @@ using System.Text;
namespace _06_UebgSaGenerics
{
class GenericStack
class GenericStack <T>
{
private class Element // Element ist eine private Hilfsklasse der Klasse StringListe
{
public T obj;
public Element next = null;
public Element(T daten) { this.obj = daten; }
public override string ToString() => obj.ToString();
}
Element anf = null, ende = null;
int anz = 0; // Sehr sinnvoll für Index-Ops
//public StringListe() { }
public void AddFirst(T daten)
{
// 1. Leere Liste
// 2. Es existiert mind. ein Element
Element neuesElement = new Element(daten); // Neues Element anlegen
anz++;
if (anf == null) // 1.Fall: Leere Liste?
anf = ende = neuesElement;
else
{
neuesElement.next = anf; // 2. Fall
anf = neuesElement;
}
}
public T GetFirst(bool removeFromStack = true)
{
if (anf == null) throw new Exception("Stapel ist leer");
T zwischen = anf.obj;
if (removeFromStack == true) anf = anf.next;
return zwischen;
}
}
}
using System;
using System.Collections.Generic;
namespace _06_UebgSaGenerics
{
......@@ -7,6 +8,7 @@ namespace _06_UebgSaGenerics
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
List<int> li = new List<int>();
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_07_MethodeSplitArray</RootNamespace>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
namespace _07_MethodeSplitArray
{
class Kfz : IComparable <Kfz>
{
string kennzeichen;
public Kfz(string kennzeichen) { this.kennzeichen = kennzeichen; }
public int CompareTo(Kfz other) => kennzeichen.CompareTo(other.kennzeichen);
}
class Program
{
//static int[] SplitArray(int limit, int[] f)
static U[] SplitArray<U>(U limit, params U[] f)
where U:IComparable<U> // ~Constraint
// ~Vertrag: SplitArray kann Felder von jedem Typ bearbeiten,
// der eine CompareTo-Methode enthält
{
List<U> erg = new List<U>();
foreach (var item in f)
{
if (item.CompareTo(limit) > 0)
erg.Add( item);
}
return erg.ToArray();
}
static int MyCompareTo(string s1, string s2) // "Hallo" | "Hallo2"
{
int limit = s1.Length < s2.Length ? s1.Length : s2.Length;
for (int i = 0; i < limit; i++)
{
int dif = s1[i] - s2[i];
if (dif != 0)
return dif;
}
return s1.Length - s2.Length;
}
static void Main(string[] args)
{
int[] f1 = SplitArray(3, 1, 3, 5, 7, 9, 11);
string[] f2 = SplitArray("Claudia", "Anton","Berta","Dieter","Emil");
Kfz[] f3 = SplitArray(new Kfz("N-AB 100"),
new Kfz("N-XY 300"),new Kfz("AB-MN 200"), new Kfz("ER-S 500"));
foreach (var item in f3)
{
Console.WriteLine(item);
}
}
}
}
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"07 MethodeSplitArray/1.0.0": {
"runtime": {
"07 MethodeSplitArray.dll": {}
}
}
}
},
"libraries": {
"07 MethodeSplitArray/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\wienkop\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\wienkop\\.nuget\\packages"
]
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment