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

2020-05-04b

parent e270826f
No related branches found
No related tags found
No related merge requests found
Showing
with 132 additions and 11 deletions
No preview for this file type
......@@ -100,6 +100,28 @@ namespace _02VerketteteListe_2
ende = vorletzter;
}
}
public void DeleteNth(int Ind)
{
// 1.Fall: Liste ist leer
// 2.Fall: Liste besteht nur aus einem Element UND Ind == 0
// 3.Fall: Liste hat mehr als ein Element
// a) Ind==0 --> DeleteFront()
// b) Ind==max -> DeleteLast()
// c) Ind < max
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
{
......
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
using System;
using System.Collections;
namespace _03_UebgMo_FiFoListe
{
......@@ -7,7 +8,7 @@ namespace _03_UebgMo_FiFoListe
class Element
{
public string name;
public Element next;
public Element(string name) { this.name = name; }
public override string ToString() => name;
......@@ -16,7 +17,8 @@ namespace _03_UebgMo_FiFoListe
int anz;
public FiFoListe()
{
anf = ende = null;
anz = 0;
}
/// <summary>
/// Fügt der Warteschlange ein neues Element hinzu
......@@ -24,7 +26,15 @@ namespace _03_UebgMo_FiFoListe
/// <param name="text"></param>
public void Push(string text)
{
Element neu = new Element(text);
anz++;
if (anf == null)
anf = ende = neu;
else
{
ende.next = neu;
ende = neu;
}
}
/// <summary>
///
......@@ -32,7 +42,8 @@ namespace _03_UebgMo_FiFoListe
/// <param name="textFeld"></param>
public void Push(params string[] textFeld)
{
foreach (string item in textFeld)
Push(item);
}
/// <summary>
/// Liefert das erste Element zurück. Es bleibt aber in der Warteschlange
......@@ -40,7 +51,10 @@ namespace _03_UebgMo_FiFoListe
/// <returns></returns>
public string First()
{
if(anf== null)
throw new ArgumentNullException("Leere Warteschlange");
else
return anf.name;
}
/// <summary>
/// Liefert Wert des ersten Ausgabeelements zurück UND entfernt dieses aus der Warteschlange
......@@ -51,14 +65,25 @@ namespace _03_UebgMo_FiFoListe
// 1.Fall: Liste ist leer
// 2.Fall: Liste besteht nur aus *einem* Element
// 3.Fall: Liste hat mehr als ein Element
if (anf == null)
throw new ArgumentNullException("Liste ist leer");
string erg = anf.name;
if (anf == ende)
anf = ende = null;
else
anf = anf.next;
anz--;
return erg;
}
/// <summary>
/// Gibt alle Elemente der Warteschlange auf dem Bildschirm aus
/// </summary>
public void WriteAll()
{
for (Element item = anf; item != null; item = item.next)
{
Console.WriteLine(item);
}
}
/// <summary>
/// liefert ein string-Feld mit allen gespeicherten Elementen zurück;
......@@ -67,12 +92,28 @@ namespace _03_UebgMo_FiFoListe
/// <returns></returns>
public string[] GetAll()
{
if (anz == 0)
return null;
string[] erg = new string[anz];
int i = 0;
for (Element tmp = anf; tmp != null; tmp = tmp.next)
{
erg[i] = tmp.name;
i++;
}
return erg;
}
public IEnumerator GetEnumerator()
{
for (Element tmp = anf; tmp != null; tmp = tmp.next)
{
yield return tmp.name;
}
}
/// <summary>
/// Anzahl der Elemente in der Warteschlange zurückgeben
/// </summary>
public int ItemCount { }
public int ItemCount { get => anz; }
}
class Program
......@@ -95,6 +136,10 @@ namespace _03_UebgMo_FiFoListe
{
Console.WriteLine($"foreach: {item}");
}
foreach (string item in f)
{
Console.WriteLine($"GetEnumerator: {item}");
}
}
}
}
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"03 UebgMo FiFoListe/1.0.0": {
"runtime": {
"03 UebgMo FiFoListe.dll": {}
}
}
}
},
"libraries": {
"03 UebgMo FiFoListe/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\03 UebgMo FiFoListe\obj\Debug\netcoreapp3.1\03 UebgMo FiFoListe.csproj.CoreCompileInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\obj\Debug\netcoreapp3.1\03 UebgMo FiFoListe.AssemblyInfoInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\obj\Debug\netcoreapp3.1\03 UebgMo FiFoListe.AssemblyInfo.cs
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\bin\Debug\netcoreapp3.1\03 UebgMo FiFoListe.exe
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\bin\Debug\netcoreapp3.1\03 UebgMo FiFoListe.deps.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\bin\Debug\netcoreapp3.1\03 UebgMo FiFoListe.runtimeconfig.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\bin\Debug\netcoreapp3.1\03 UebgMo FiFoListe.runtimeconfig.dev.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\bin\Debug\netcoreapp3.1\03 UebgMo FiFoListe.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\bin\Debug\netcoreapp3.1\03 UebgMo FiFoListe.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\obj\Debug\netcoreapp3.1\03 UebgMo FiFoListe.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\obj\Debug\netcoreapp3.1\03 UebgMo FiFoListe.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\03 UebgMo FiFoListe\obj\Debug\netcoreapp3.1\03 UebgMo FiFoListe.genruntimeconfig.cache
File added
File added
86c8e15dd33445635927cfaf398408205fd11473
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment