Skip to content
Snippets Groups Projects
Commit 84ef7b5f authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

2020-05-11b Mo

parent b9258b07
Branches
No related tags found
No related merge requests found
Showing
with 105 additions and 17 deletions
No preview for this file type
...@@ -125,6 +125,17 @@ namespace _02VerketteteListe_2 ...@@ -125,6 +125,17 @@ namespace _02VerketteteListe_2
// an der gespeicherten Pos. weitergemacht. // an der gespeicherten Pos. weitergemacht.
} }
} }
public IEnumerable Iterate(int offset=0)
{
Element item = anf;
for (int i = 0; i < offset; i++)
item = item.next;
while( item != null)
{
yield return item.name;
item = item.next;
}
}
// foreach --> GetEnumerator() merkt sich die Pos nach yield return und liefert ("Anton") // foreach --> GetEnumerator() merkt sich die Pos nach yield return und liefert ("Anton")
// item = "Anton" // item = "Anton"
...@@ -257,7 +268,7 @@ namespace _02VerketteteListe_2 ...@@ -257,7 +268,7 @@ namespace _02VerketteteListe_2
//l1.Print(); //l1.Print();
l1.AddBeforeNth(2, "Bodo"); l1.AddBeforeNth(2, "Bodo");
l1.Print(); l1.Print();
foreach (string item in l1.Filter("er")) foreach (string item in l1.Iterate(2))
{ {
Console.WriteLine($"foreach: {item}"); Console.WriteLine($"foreach: {item}");
} }
......
...@@ -20,10 +20,11 @@ namespace _03_UebgDi_ZyklischeListe ...@@ -20,10 +20,11 @@ namespace _03_UebgDi_ZyklischeListe
anf = ende = neuesElement; anf = ende = neuesElement;
else else
ende = ende.next = neuesElement; // 3. Neues Element am Ende anfügen ende = ende.next = neuesElement; // 3. Neues Element am Ende anfügen
ende.next = anf; // Zyklus schließen: Ende auf Anf verweisen lassen
} }
public void CloseCycle() public void CloseCycle()
{ {
ende.next = anf; ende.next = anf; // Zyklus schließen: Ende auf Anf verweisen lassen
} }
public void Print() public void Print()
{ {
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -15,25 +15,47 @@ namespace _04_UebgMo_ZyklischeListe ...@@ -15,25 +15,47 @@ namespace _04_UebgMo_ZyklischeListe
Element iterator = null; Element iterator = null;
public void AddEnd(string name) public void AddEnd(string name)
{ {
Element neuesElement = new Element(name); // 1. Neues Element anlegen
if (anf == null) // 2. Leere Liste?
anf = ende = neuesElement;
else
{
ende.next = neuesElement; // 3. Neues Element am Ende anfügen
ende = ende.next;
}
ende.next = anf;
iterator = ende;
} }
public void CloseCycle() public void CloseCycle()
{ {
ende.next = anf;
} }
public void Print() public void Print()
{ {
if (anf == null)
return;
// Wir wissen: Es existiert mindestens EIN Element
Element tmp = anf;
do
{
Console.WriteLine(tmp);
tmp = tmp.next;
} while (tmp != null && tmp != anf);
} }
public void SetIterator(int offset = 0) public void SetIterator(int offset = 0)
{ {
iterator = anf;
} for (int i = 0; i < offset; i++)
public string GetName() ; iterator = iterator.next;
public void MoveNext() { }
} }
public string GetName() => iterator.name;
public void MoveNext() { iterator = iterator.next; }
}
// Programmierer 1
// =========================================================== // ===========================================================
// Anwender
class Program class Program
{ {
static void Main(string[] args) static void Main(string[] args)
...@@ -41,7 +63,7 @@ namespace _04_UebgMo_ZyklischeListe ...@@ -41,7 +63,7 @@ namespace _04_UebgMo_ZyklischeListe
CycleList cl = new CycleList(); CycleList cl = new CycleList();
cl.AddEnd("Anton"); cl.AddEnd("Anton");
cl.AddEnd("Berta"); cl.AddEnd("Berta");
cl.CloseCycle(); //cl.CloseCycle();
cl.Print(); cl.Print();
Console.WriteLine("-------------"); Console.WriteLine("-------------");
cl.AddEnd("Claudia"); cl.AddEnd("Claudia");
......
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"04 UebgMo ZyklischeListe/1.0.0": {
"runtime": {
"04 UebgMo ZyklischeListe.dll": {}
}
}
}
},
"libraries": {
"04 UebgMo ZyklischeListe/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
File added
File added
File added
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\wienkop\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\wienkop\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
\ No newline at end of file
c0523642d3f3714f80c0cf31b3f8720f51a0bc09
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\bin\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.exe
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\bin\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.deps.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\bin\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.runtimeconfig.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\bin\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.runtimeconfig.dev.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\bin\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\bin\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\obj\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.csproj.CoreCompileInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\obj\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.AssemblyInfoInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\obj\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.AssemblyInfo.cs
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\obj\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\obj\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\obj\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.genruntimeconfig.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\04 UebgMo ZyklischeListe\obj\Debug\netcoreapp3.1\04 UebgMo ZyklischeListe.csprojAssemblyReference.cache
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment