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

2021-03-29 Verkettete Liste

parent 2618e263
No related branches found
No related tags found
No related merge requests found
...@@ -8,5 +8,51 @@ namespace _02_4_VerketteteStrukturenIntro ...@@ -8,5 +8,51 @@ namespace _02_4_VerketteteStrukturenIntro
{ {
public int zahl; public int zahl;
public LItem next; public LItem next;
public LItem(int k) { zahl = k; next = null; }
}
class Liste
{
public LItem first, last;
public Liste()
{
first = last = null;
}
public void AddLast(int k)
{
LItem neu = new LItem(k);
if (first == null)
first = last = neu;
else
{
last.next = neu; // Schritt (1)
last = neu; // Schritt (2)
}
}
public void AddFirst(int k)
{
LItem neu = new LItem(k);
if (first == null)
first = last = neu;
else
{
neu.next = first; // Schritt (1)
first = neu; // Schritt (2)
}
}
public void Ausgabe()
{
for (LItem item = first; item != null; item = item.next)
Console.WriteLine(item.zahl);
//LItem item = first;
//while (item!=null)
//{
// Console.WriteLine(item.zahl);
// item = item.next;
//}
}
} }
} }
...@@ -7,13 +7,36 @@ namespace _02_4_VerketteteStrukturenIntro ...@@ -7,13 +7,36 @@ namespace _02_4_VerketteteStrukturenIntro
static void Main(string[] args) static void Main(string[] args)
{ {
// int[] f = new int[500]; // int[] f = new int[500];
LItem e1 = new LItem(); #region Listenaufbau Intro
e1.zahl = 10; //LItem e1 = new LItem(10);
// Schritt 1: Anfrage an das BS: Gib Speicher für ein LItem
// BS antwortet: Speicher ab Adresse 100.000
// Schritt 2: Initialisierung des Speichers bei 100.000
// (100.000).zahl = 10;
// (100.000).next = null (0)
// Rückgabe des new() - Befehls --> 100.000
// e1 = 100.000;
LItem e2 = new LItem(); //LItem e2 = new LItem(20);
e2.zahl = 20; // e2 = 200.000;
e1.next = e2; //e1.next = e2;
// (100.000).next = 200.000
#endregion
Liste l1 = new Liste();
//Liste l2 = new Liste();
l1.AddLast(10);
l1.AddLast(20);
l1.AddLast(30);
for (int i = 100; i < 110; i++)
l1.AddLast(i);
l1.AddFirst(5);
l1.Ausgabe();
} }
} }
} }
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_03_UbgKlasseTime_Mo</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _03_UbgKlasseTime_Mo
{
class Program
{
static void Main(string[] args)
{
Time t1 = new Time(9, 45);
Time t3 = "11:30";
Time t2 = t1 + "1:30" + 15;
Console.WriteLine(t2);
TimeSpan ts1 = t3 - t1;
Console.WriteLine(t2);
Console.WriteLine(ts1.TotalMins);
Console.WriteLine(ts1);
if (t2)
Console.WriteLine("Guten Morgen");
else
Console.WriteLine("Guten Tag");
if (t2 == t3)
Console.WriteLine("Die Uhrzeiten sind gleich!");
else
Console.WriteLine("Die Uhrzeiten stimmen nicht überein");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace _03_UbgKlasseTime_Mo
{
class Time
{
int time;
public Time(int stunden, int minuten)
{
time = stunden * 60 + minuten;
}
private Time(int minuten)
{
time = minuten;
}
public static implicit operator Time(string s)
{
string[] d = s.Split(':');
return new Time(Convert.ToInt32(d[0]), Convert.ToInt32(d[1]));
}
public static implicit operator Time (int k) => new Time(k);
//public static implicit operator bool(Time t) => t.time < 12*60;
public static bool operator true(Time t) => t.time < 12 * 60;
public static bool operator false(Time t) => t.time >= 12 * 60;
public static Time operator +(Time t1, Time t2) => new Time(t1.time + t2.time);
public override string ToString() => $"{time / 60}:{time % 60}";
public static TimeSpan operator -(Time t2, Time t1)
=> new TimeSpan(t2.time-t1.time);
public static bool operator ==(Time t1, Time t2) => t1.time == t2.time;
public static bool operator !=(Time t1, Time t2) => !(t1==t2);
}
class TimeSpan
{
int span;
public TimeSpan(int minuten) { span = minuten; }
public int TotalMins { get => span; }
public override string ToString() => $"{span / 60}:{span % 60} Stunden:Mins";
}
}
...@@ -15,9 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01-3 TestPersonalausweis", ...@@ -15,9 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01-3 TestPersonalausweis",
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02-1 OpUeberladungBrueche", "02-1 OpUeberladungBrueche\02-1 OpUeberladungBrueche.csproj", "{0CEC8CDB-1B65-4A3D-B6BD-5DE722BEE96D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02-1 OpUeberladungBrueche", "02-1 OpUeberladungBrueche\02-1 OpUeberladungBrueche.csproj", "{0CEC8CDB-1B65-4A3D-B6BD-5DE722BEE96D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "02-UbgKlasseTime", "02-UbgKlasseTime\02-UbgKlasseTime.csproj", "{A0A79CA1-F22A-4890-9A24-136FBAFBD0B4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02-UbgKlasseTime-Di", "02-UbgKlasseTime\02-UbgKlasseTime-Di.csproj", "{A0A79CA1-F22A-4890-9A24-136FBAFBD0B4}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "02-4 VerketteteStrukturenIntro", "02-4 VerketteteStrukturenIntro\02-4 VerketteteStrukturenIntro.csproj", "{1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02-4 VerketteteStrukturenIntro", "02-4 VerketteteStrukturenIntro\02-4 VerketteteStrukturenIntro.csproj", "{1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03-UbgKlasseTime-Mo", "03-UbgKlasseTime-Mo\03-UbgKlasseTime-Mo.csproj", "{DD51B164-0F20-47B9-94C4-549CE555DDC2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -57,6 +59,10 @@ Global ...@@ -57,6 +59,10 @@ Global
{1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}.Debug|Any CPU.Build.0 = Debug|Any CPU {1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}.Release|Any CPU.ActiveCfg = Release|Any CPU {1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}.Release|Any CPU.Build.0 = Release|Any CPU {1FC21BA1-47A7-4466-BA80-A29C0AFD5FB6}.Release|Any CPU.Build.0 = Release|Any CPU
{DD51B164-0F20-47B9-94C4-549CE555DDC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD51B164-0F20-47B9-94C4-549CE555DDC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD51B164-0F20-47B9-94C4-549CE555DDC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD51B164-0F20-47B9-94C4-549CE555DDC2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment