erweiterung

This commit is contained in:
2023-03-23 15:55:13 +01:00
parent 33e49f846c
commit 09c8eab938
39 changed files with 1167 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeispielGenerischeTypen
{
public class Stapel<T> where T : IKarte
{
private List<T> karten;
public Stapel()
{
karten = new List<T>();
}
public void Push(T karte)
{
karten.Add(karte);
}
public T Pop()
{
if (karten.Count == 0)
{
throw new InvalidOperationException("Der Stapel ist leer.");
}
int lastIndex = karten.Count - 1;
T karte = karten[lastIndex];
karten.RemoveAt(lastIndex);
return karte;
}
public bool IsEmpty()
{
return karten.Count == 0;
}
}
}