This commit is contained in:
Lendaia Mirai
2025-11-02 00:03:25 +01:00
parent 3301d77783
commit 0ffa65cac7
8 changed files with 1654 additions and 711 deletions

View File

@@ -1,274 +1,274 @@
using System;
using System.Collections;
using System.Collections.Generic;
// using System;
// using System.Collections;
// using System.Collections.Generic;
namespace OE.ALGA.Adatszerkezetek
{
public class TombVerem<T> : Verem<T>
{
T[] tomb;
int n = 0;
public TombVerem(int l)
{
tomb = new T[l];
}
public bool Ures
{
get { return n == 0; }
}
// namespace OE.ALGA.Adatszerkezetek
// {
// public class TombVerem<T> : Verem<T>
// {
// T[] tomb;
// int n = 0;
// public TombVerem(int l)
// {
// tomb = new T[l];
// }
// public bool Ures
// {
// get { return n == 0; }
// }
public T Felso()
{
return tomb[n - 1];
}
// public T Felso()
// {
// return tomb[n - 1];
// }
public void Verembe(T ertek)
{
if (n < tomb.Length)
{
tomb[n] = ertek;
n++;
}
else
{
throw new NincsHelyKivetel();
}
}
// public void Verembe(T ertek)
// {
// if (n < tomb.Length)
// {
// tomb[n] = ertek;
// n++;
// }
// else
// {
// throw new NincsHelyKivetel();
// }
// }
public T Verembol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
T ertek = tomb[n - 1];
n--;
return ertek;
}
// public T Verembol()
// {
// if (Ures)
// {
// throw new NincsElemKivetel();
// }
// else
// {
// T ertek = tomb[n - 1];
// n--;
// return ertek;
// }
}
}
public class TombSor<T> : Sor<T>
{
T[] tomb;
int n = 0;
public TombSor(int l)
{
tomb = new T[l];
}
// }
// }
// public class TombSor<T> : Sor<T>
// {
// T[] tomb;
// int n = 0;
// public TombSor(int l)
// {
// tomb = new T[l];
// }
public bool Ures
{
get { return n == 0; }
}
// public bool Ures
// {
// get { return n == 0; }
// }
public T Elso()
{
return tomb[0];
}
// public T Elso()
// {
// return tomb[0];
// }
public void Sorba(T ertek)
{
if (n < tomb.Length)
{
tomb[n] = ertek;
n++;
}
else
{
throw new NincsHelyKivetel();
}
}
// public void Sorba(T ertek)
// {
// if (n < tomb.Length)
// {
// tomb[n] = ertek;
// n++;
// }
// else
// {
// throw new NincsHelyKivetel();
// }
// }
public T Sorbol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
T ertek = tomb[0];
T[] tmp = new T[tomb.Length];
n--;
for (int i = 1; i < tomb.Length; i++)
{
tmp[i - 1] = tomb[i];
}
tomb = tmp;
return ertek;
}
}
}
public class TombLista<T> : Lista<T>, IEnumerable<T>
{
T[] tomb;
int n = 0;
// public T Sorbol()
// {
// if (Ures)
// {
// throw new NincsElemKivetel();
// }
// else
// {
// T ertek = tomb[0];
// T[] tmp = new T[tomb.Length];
// n--;
// for (int i = 1; i < tomb.Length; i++)
// {
// tmp[i - 1] = tomb[i];
// }
// tomb = tmp;
// return ertek;
// }
// }
// }
// public class TombLista<T> : Lista<T>, IEnumerable<T>
// {
// T[] tomb;
// int n = 0;
public bool Ures
{
get { return n <= 0; }
}
public TombLista()
{
tomb = new T[1];
}
// public bool Ures
// {
// get { return n <= 0; }
// }
// public TombLista()
// {
// tomb = new T[1];
// }
public int Elemszam
{
get { return n; }
}
// public int Elemszam
// {
// get { return n; }
// }
public void Bejar(Action<T> muvelet)
{
for (int i = 0; i < n; i++)
{
muvelet?.Invoke(tomb[i]);
}
}
// public void Bejar(Action<T> muvelet)
// {
// for (int i = 0; i < n; i++)
// {
// muvelet?.Invoke(tomb[i]);
// }
// }
public void Beszur(int index, T ertek)
{
if (index < 0)
{
throw new HibasIndexKivetel();
}
else
{
T[] tmp = new T[tomb.Length * 2];
for (int i = 0; i < index; i++)
{
tmp[i] = tomb[i];
}
tmp[index] = ertek;
for (int i = index + 1; i < tomb.Length; i++)
{
tmp[i] = tomb[i - 1];
}
tomb = tmp;
n++;
}
}
// public void Beszur(int index, T ertek)
// {
// if (index < 0)
// {
// throw new HibasIndexKivetel();
// }
// else
// {
// T[] tmp = new T[tomb.Length * 2];
// for (int i = 0; i < index; i++)
// {
// tmp[i] = tomb[i];
// }
// tmp[index] = ertek;
// for (int i = index + 1; i < tomb.Length; i++)
// {
// tmp[i] = tomb[i - 1];
// }
// tomb = tmp;
// n++;
// }
// }
public IEnumerator<T> GetEnumerator()
{
foreach (T t in tomb)
{
if (t != null)
{
yield return t;
}
}
}
// public IEnumerator<T> GetEnumerator()
// {
// foreach (T t in tomb)
// {
// if (t != null)
// {
// yield return t;
// }
// }
// }
public void Hozzafuz(T ertek)
{
if (n < tomb.Length)
{
tomb[n] = ertek;
n++;
}
else
{
T[] tmp = new T[tomb.Length * 2];
for (int i = 0; i < tomb.Length; i++)
{
tmp[i] = tomb[i];
}
tmp[n] = ertek;
tomb = tmp;
n++;
}
}
// public void Hozzafuz(T ertek)
// {
// if (n < tomb.Length)
// {
// tomb[n] = ertek;
// n++;
// }
// else
// {
// T[] tmp = new T[tomb.Length * 2];
// for (int i = 0; i < tomb.Length; i++)
// {
// tmp[i] = tomb[i];
// }
// tmp[n] = ertek;
// tomb = tmp;
// n++;
// }
// }
public T Kiolvas(int index)
{
if (index < 0 || index >= tomb.Length)
{
throw new HibasIndexKivetel();
}
return tomb[index];
}
// public T Kiolvas(int index)
// {
// if (index < 0 || index >= tomb.Length)
// {
// throw new HibasIndexKivetel();
// }
// return tomb[index];
// }
public void Modosit(int index, T ertek)
{
if (index < 0 && index < tomb.Length)
{
throw new HibasIndexKivetel();
}
else
{
tomb[index] = ertek;
}
}
// public void Modosit(int index, T ertek)
// {
// if (index < 0 && index < tomb.Length)
// {
// throw new HibasIndexKivetel();
// }
// else
// {
// tomb[index] = ertek;
// }
// }
public void Torol(T ertek)
{
int m = n;
T[] tmp = new T[tomb.Length];
int index = 0;
for (int i = 0; i < m; i++)
{
if (ertek.Equals(tomb[i]))
{
n--;
continue;
}
tmp[index] = tomb[i];
index++;
}
tomb = tmp;
}
// public void Torol(T ertek)
// {
// int m = n;
// T[] tmp = new T[tomb.Length];
// int index = 0;
// for (int i = 0; i < m; i++)
// {
// if (ertek.Equals(tomb[i]))
// {
// n--;
// continue;
// }
// tmp[index] = tomb[i];
// index++;
// }
// tomb = tmp;
// }
IEnumerator IEnumerable.GetEnumerator()
{
TombListaBejaro<T> bejaro = new TombListaBejaro<T>(tomb, n);
return bejaro;
}
}
public class TombListaBejaro<T> : IEnumerator<T>
{
T[] e;
int n;
int aktualisindex;
T current;
public T Current
{
get { return current; }
}
public TombListaBejaro(T[] e, int n)
{
this.n = n;
this.e = e;
aktualisindex = 0;
current = e[0];
}
// IEnumerator IEnumerable.GetEnumerator()
// {
// TombListaBejaro<T> bejaro = new TombListaBejaro<T>(tomb, n);
// return bejaro;
// }
// }
// public class TombListaBejaro<T> : IEnumerator<T>
// {
// T[] e;
// int n;
// int aktualisindex;
// T current;
// public T Current
// {
// get { return current; }
// }
// public TombListaBejaro(T[] e, int n)
// {
// this.n = n;
// this.e = e;
// aktualisindex = 0;
// current = e[0];
// }
object IEnumerator.Current => Current;
// object IEnumerator.Current => Current;
public void Dispose()
{
throw new NotImplementedException();
}
// public void Dispose()
// {
// throw new NotImplementedException();
// }
public bool MoveNext()
{
if (aktualisindex < n - 1)
{
aktualisindex++;
return true;
}
else
{
return false;
}
}
// public bool MoveNext()
// {
// if (aktualisindex < n - 1)
// {
// aktualisindex++;
// return true;
// }
// else
// {
// return false;
// }
// }
public void Reset()
{
aktualisindex = -1;
}
}
}
// public void Reset()
// {
// aktualisindex = -1;
// }
// }
// }

View File

@@ -1,325 +1,325 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
// using System;
// using System.Collections;
// using System.Collections.Generic;
// using System.Runtime.CompilerServices;
namespace OE.ALGA.Adatszerkezetek;
// namespace OE.ALGA.Adatszerkezetek;
public class LancElem<T>
{
public T tart;
public LancElem<T>? kov;
public LancElem<T>? elozo;
// public class LancElem<T>
// {
// public T tart;
// public LancElem<T>? kov;
// public LancElem<T>? elozo;
public LancElem(T tart, LancElem<T>? kov, LancElem<T>? elozo)
{
this.tart = tart;
this.kov = kov;
this.elozo = elozo;
}
}
public class LancoltVerem<T> : Verem<T>
{
LancElem<T>? fej;
LancElem<T>? teteje;
public LancoltVerem()
{
}
public void Felszabadit()
{
// public LancElem(T tart, LancElem<T>? kov, LancElem<T>? elozo)
// {
// this.tart = tart;
// this.kov = kov;
// this.elozo = elozo;
// }
// }
// public class LancoltVerem<T> : Verem<T>
// {
// LancElem<T>? fej;
// LancElem<T>? teteje;
// public LancoltVerem()
// {
// }
// public void Felszabadit()
// {
}
public bool Ures
{
get { return fej == null; }
}
// }
// public bool Ures
// {
// get { return fej == null; }
// }
public T Felso()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
LancElem<T>? tmp = fej;
while (tmp.kov != null)
{
tmp = tmp.kov;
}
teteje = tmp;
return tmp.tart;
}
}
// public T Felso()
// {
// if (Ures)
// {
// throw new NincsElemKivetel();
// }
// else
// {
// LancElem<T>? tmp = fej;
// while (tmp.kov != null)
// {
// tmp = tmp.kov;
// }
// teteje = tmp;
// return tmp.tart;
// }
// }
public void Verembe(T ertek)
{
if (Ures)
{
fej = new LancElem<T>(ertek, null, null);
teteje = fej;
}
else
{
teteje.kov = new LancElem<T>(ertek, null, teteje);
teteje = teteje.kov;
}
}
// public void Verembe(T ertek)
// {
// if (Ures)
// {
// fej = new LancElem<T>(ertek, null, null);
// teteje = fej;
// }
// else
// {
// teteje.kov = new LancElem<T>(ertek, null, teteje);
// teteje = teteje.kov;
// }
// }
public T Verembol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
if (teteje.elozo == null)
{
T ertek = fej.tart;
fej = null;
teteje = fej;
return ertek;
}
else
{
T ertek = Felso();
teteje.elozo.kov = null;
teteje = teteje.elozo;
return ertek;
}
}
}
}
public class LancoltSor<T> : Sor<T>
{
LancElem<T>? fej;
LancElem<T>? vege;
public bool Ures
{
get { return ( vege == null); }
}
public LancoltSor()
{
// public T Verembol()
// {
// if (Ures)
// {
// throw new NincsElemKivetel();
// }
// else
// {
// if (teteje.elozo == null)
// {
// T ertek = fej.tart;
// fej = null;
// teteje = fej;
// return ertek;
// }
// else
// {
// T ertek = Felso();
// teteje.elozo.kov = null;
// teteje = teteje.elozo;
// return ertek;
// }
// }
// }
// }
// public class LancoltSor<T> : Sor<T>
// {
// LancElem<T>? fej;
// LancElem<T>? vege;
// public bool Ures
// {
// get { return ( vege == null); }
// }
// public LancoltSor()
// {
}
public void Felszabadit()
{
// }
// public void Felszabadit()
// {
}
public T Elso()
{
return fej.tart;
}
// }
// public T Elso()
// {
// return fej.tart;
// }
public void Sorba(T ertek)
{
if (Ures)
{
fej = new LancElem<T>(ertek, null, null);
vege = fej;
}
else
{
LancElem<T>? tmp = fej;
while (tmp.kov != null)
{
tmp = tmp.kov;
}
tmp.kov = new LancElem<T>(ertek, null, tmp);
vege = tmp.kov;
}
}
// public void Sorba(T ertek)
// {
// if (Ures)
// {
// fej = new LancElem<T>(ertek, null, null);
// vege = fej;
// }
// else
// {
// LancElem<T>? tmp = fej;
// while (tmp.kov != null)
// {
// tmp = tmp.kov;
// }
// tmp.kov = new LancElem<T>(ertek, null, tmp);
// vege = tmp.kov;
// }
// }
public T Sorbol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
if (vege.elozo == null)
{
T ertek = vege.tart;
vege = null;
return ertek;
}
else
{
T ertek = fej.tart;
fej = fej.kov;
fej.elozo = null;
return ertek;
}
}
}
}
public class LancoltLista<T> : Lista<T>, IEnumerable<T>
{
int n;
LancElem<T>? fej;
// public T Sorbol()
// {
// if (Ures)
// {
// throw new NincsElemKivetel();
// }
// else
// {
// if (vege.elozo == null)
// {
// T ertek = vege.tart;
// vege = null;
// return ertek;
// }
// else
// {
// T ertek = fej.tart;
// fej = fej.kov;
// fej.elozo = null;
// return ertek;
// }
// }
// }
// }
// public class LancoltLista<T> : Lista<T>, IEnumerable<T>
// {
// int n;
// LancElem<T>? fej;
public int Elemszam
{
get { return n; }
}
public LancoltLista()
{
// public int Elemszam
// {
// get { return n; }
// }
// public LancoltLista()
// {
}
public void Felszabadit()
{
// }
// public void Felszabadit()
// {
}
// }
public void Bejar(Action<T> muvelet)
{
for (int i = 0; i < n; i++)
{
muvelet(Indexedik(i).tart);
}
}
// public void Bejar(Action<T> muvelet)
// {
// for (int i = 0; i < n; i++)
// {
// muvelet(Indexedik(i).tart);
// }
// }
public void Beszur(int index, T ertek)
{
if (fej == null)
{
if (index == 0)
{
Hozzafuz(ertek);
}
else
{
throw new HibasIndexKivetel();
}
}
else
{
if (index == 0)
{
fej.elozo = new LancElem<T>(ertek, fej, null);
fej = fej.elozo;
n++;
}
else if (index == n)
{
Hozzafuz(ertek);
n++;
}
else
{
LancElem<T>? xd = Indexedik(index).elozo;
xd.kov = new LancElem<T>(ertek, Indexedik(index), xd.kov);
xd.kov.kov.elozo = xd.kov;
n++;
}
}
}
// public void Beszur(int index, T ertek)
// {
// if (fej == null)
// {
// if (index == 0)
// {
// Hozzafuz(ertek);
// }
// else
// {
// throw new HibasIndexKivetel();
// }
// }
// else
// {
// if (index == 0)
// {
// fej.elozo = new LancElem<T>(ertek, fej, null);
// fej = fej.elozo;
// n++;
// }
// else if (index == n)
// {
// Hozzafuz(ertek);
// n++;
// }
// else
// {
// LancElem<T>? xd = Indexedik(index).elozo;
// xd.kov = new LancElem<T>(ertek, Indexedik(index), xd.kov);
// xd.kov.kov.elozo = xd.kov;
// n++;
// }
// }
// }
public void Hozzafuz(T ertek)
{
if (Elemszam < 1)
{
fej = new LancElem<T>(ertek, null, null);
n++;
}
else
{
LancElem<T> asd = Indexedik(n-1);
asd.kov = new LancElem<T>(ertek, null, asd);
n++;
}
}
// public void Hozzafuz(T ertek)
// {
// if (Elemszam < 1)
// {
// fej = new LancElem<T>(ertek, null, null);
// n++;
// }
// else
// {
// LancElem<T> asd = Indexedik(n-1);
// asd.kov = new LancElem<T>(ertek, null, asd);
// n++;
// }
// }
public T Kiolvas(int index)
{
return Indexedik(index).tart;
}
// public T Kiolvas(int index)
// {
// return Indexedik(index).tart;
// }
public void Modosit(int index, T ertek)
{
Indexedik(index).tart = ertek;
}
// public void Modosit(int index, T ertek)
// {
// Indexedik(index).tart = ertek;
// }
public void Torol(T ertek)
{
LancElem<T> tmp = fej;
while (tmp.kov != null)
{
if (ertek.Equals(tmp.tart))
{
tmp.elozo.kov = tmp.kov;
tmp.kov.elozo = tmp.elozo;
// public void Torol(T ertek)
// {
// LancElem<T> tmp = fej;
// while (tmp.kov != null)
// {
// if (ertek.Equals(tmp.tart))
// {
// tmp.elozo.kov = tmp.kov;
// tmp.kov.elozo = tmp.elozo;
}
tmp = tmp.kov;
}
}
private LancElem<T> Indexedik(int index)
{
LancElem<T>? tmp = fej;
for (int i = 0; i < index; i++)
{
tmp = tmp.kov;
}
return tmp;
}
// }
// tmp = tmp.kov;
// }
// }
// private LancElem<T> Indexedik(int index)
// {
// LancElem<T>? tmp = fej;
// for (int i = 0; i < index; i++)
// {
// tmp = tmp.kov;
// }
// return tmp;
// }
public IEnumerator<T> GetEnumerator()
{
LancElem<T> tmp = fej;
while(tmp != null)
{
if (tmp.tart != null)
{
yield return tmp.tart;
}
tmp = tmp.kov;
}
}
// public IEnumerator<T> GetEnumerator()
// {
// LancElem<T> tmp = fej;
// while(tmp != null)
// {
// if (tmp.tart != null)
// {
// yield return tmp.tart;
// }
// tmp = tmp.kov;
// }
// }
IEnumerator IEnumerable.GetEnumerator()
{
LancoltListaBejaro<T> bejaro = new LancoltListaBejaro<T>(this.fej);
return bejaro;
}
}
class LancoltListaBejaro<T> : IEnumerator<T>
{
LancElem<T> fej;
LancElem<T> aktualisElem;
public T Current
{
get{ return aktualisElem.tart; }
}
// IEnumerator IEnumerable.GetEnumerator()
// {
// LancoltListaBejaro<T> bejaro = new LancoltListaBejaro<T>(this.fej);
// return bejaro;
// }
// }
// class LancoltListaBejaro<T> : IEnumerator<T>
// {
// LancElem<T> fej;
// LancElem<T> aktualisElem;
// public T Current
// {
// get{ return aktualisElem.tart; }
// }
object IEnumerator.Current => Current;
public LancoltListaBejaro(LancElem<T> fej)
{
this.fej = fej;
aktualisElem = fej;
}
// object IEnumerator.Current => Current;
// public LancoltListaBejaro(LancElem<T> fej)
// {
// this.fej = fej;
// aktualisElem = fej;
// }
public void Dispose()
{
throw new NotImplementedException();
}
// public void Dispose()
// {
// throw new NotImplementedException();
// }
public bool MoveNext()
{
if (aktualisElem.kov == null)
{
return false;
}
{
aktualisElem = aktualisElem.kov;
return true;
}
}
// public bool MoveNext()
// {
// if (aktualisElem.kov == null)
// {
// return false;
// }
// {
// aktualisElem = aktualisElem.kov;
// return true;
// }
// }
public void Reset()
{
aktualisElem = fej;
}
}
// public void Reset()
// {
// aktualisElem = fej;
// }
// }

View File

@@ -1,40 +1,137 @@
using System;
// using System;
// using System.Drawing;
namespace OE.ALGA;
// namespace OE.ALGA;
public class FaElem<T> where T : IComparable
{
public T tart;
public FaElem<T>? bal;
public FaElem<T>? jobb;
// internal class FaElem<T> where T : IComparable
// {
// public T? tart;
// public FaElem<T>? bal;
// public FaElem<T>? jobb;
public FaElem(T tart, FaElem<T>? bal, FaElem<T>? jobb)
{
this.tart = tart;
this.bal = bal;
this.jobb = jobb;
}
}
public class FaHalmaz<T> : Halmaz<T> where T : IComparable
{
FaElem<T>? gyoker;
public void Bejar(Action<T> muvelet)
{
throw new NotImplementedException();
}
// public FaElem(T? tart, FaElem<T>? bal, FaElem<T>? jobb)
// {
// this.tart = tart;
// this.bal = bal;
// this.jobb = jobb;
// }
// }
// public class FaHalmaz<T> : Halmaz<T> where T : IComparable
// {
// FaElem<T>? gyoker;
// public void Bejar(Action<T> muvelet)
// {
// throw new NotImplementedException();
// }
public void Beszur(T ertek)
{
throw new NotImplementedException();
}
// private static FaElem<T> ReszfabaBeszur(FaElem<T> p, T ertek)
// {
// if (p == null)
// {
// FaElem<T> uj = new FaElem<T>(ertek, null, null);
// return uj;
// }
// else
// {
// if (p.tart.CompareTo(ertek) > 0)
// {
// p.bal = ReszfabaBeszur(p.bal, ertek);
// }
// else
// {
// if (p.tart.CompareTo(ertek) < 0)
// {
// p.jobb = ReszfabaBeszur(p.jobb, ertek);
// }
// }
// return p;
// }
// }
// public void Beszur(T ertek)
// {
// gyoker = ReszfabaBeszur(gyoker, ertek);
// }
public bool Eleme(T ertek)
{
throw new NotImplementedException();
}
// private static FaElem<T> ReszfaEleme(FaElem<T> p, T ertek)
// {
// FaElem<T>? tmp = null;
// if (p == null)
// {
// return tmp;
// }
// else
// {
// if (p.tart.CompareTo(ertek) > 0)
// {
// tmp = ReszfaEleme(p.bal, ertek);
// }
// else if (p.tart.CompareTo(ertek) < 0)
// {
// tmp = ReszfabaBeszur(p.jobb, ertek);
// }
// else
// {
// return tmp;
// }
// return tmp;
// }
// }
// public bool Eleme(T ertek)
// {
// return !(ReszfaEleme(gyoker, ertek) == null);
// }
// private static FaElem<T> KetGyerekesTorles(FaElem<T> p, FaElem<T> ertek)
// {
// if (p.jobb != null)
// {
// p.jobb = KetGyerekesTorles(p.jobb, ertek);
// return p;
// }
// else
// {
// ertek.tart = p.tart;
// p = p.bal;
// return p;
public void Torol(T ertek)
{
throw new NotImplementedException();
}
}
// }
// }
// private static FaElem<T> ReszfabolTorol(FaElem<T> p, T ertek)
// {
// if (p == null)
// {
// throw new NincsElemKivetel();
// }
// if (p.tart.CompareTo(ertek) < 0)
// {
// p.bal = ReszfabolTorol(p.bal, ertek);
// }
// else if (p.tart.CompareTo(ertek) > 0)
// {
// p.jobb = ReszfabolTorol(p.jobb, ertek);
// }
// else
// {
// if (p.jobb == null && p.bal == null)
// {
// p = null;
// }
// else if (p.jobb == null && p.bal != null)
// {
// p = p.bal;
// }
// else if (p.jobb != null && p.bal == null)
// {
// p = p.jobb;
// }
// else
// {
// p = KetGyerekesTorles(p, p);
// }
// }
// return p;
// }
// public void Torol(T ertek)
// {
// ReszfabolTorol(gyoker, ertek);
// }
// }

View File

@@ -4,5 +4,271 @@ using System.Collections.Generic;
namespace OE.ALGA.Adatszerkezetek
{
// 3. heti labor feladat - Tesztek: 03_TombImplementacioTesztek.cs
public class TombVerem<T> : Verem<T>
{
T[] tomb;
int n = 0;
public TombVerem(int l)
{
tomb = new T[l];
}
public bool Ures
{
get { return n == 0; }
}
public T Felso()
{
return tomb[n - 1];
}
public void Verembe(T ertek)
{
if (n < tomb.Length)
{
tomb[n] = ertek;
n++;
}
else
{
throw new NincsHelyKivetel();
}
}
public T Verembol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
T ertek = tomb[n - 1];
n--;
return ertek;
}
}
}
public class TombSor<T> : Sor<T>
{
T[] tomb;
int n = 0;
public TombSor(int l)
{
tomb = new T[l];
}
public bool Ures
{
get { return n == 0; }
}
public T Elso()
{
return tomb[0];
}
public void Sorba(T ertek)
{
if (n < tomb.Length)
{
tomb[n] = ertek;
n++;
}
else
{
throw new NincsHelyKivetel();
}
}
public T Sorbol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
T ertek = tomb[0];
T[] tmp = new T[tomb.Length];
n--;
for (int i = 1; i < tomb.Length; i++)
{
tmp[i - 1] = tomb[i];
}
tomb = tmp;
return ertek;
}
}
}
public class TombLista<T> : Lista<T>, IEnumerable<T>
{
T[] tomb;
int n = 0;
public bool Ures
{
get { return n <= 0; }
}
public TombLista()
{
tomb = new T[1];
}
public int Elemszam
{
get { return n; }
}
public void Bejar(Action<T> muvelet)
{
for (int i = 0; i < n; i++)
{
muvelet?.Invoke(tomb[i]);
}
}
public void Beszur(int index, T ertek)
{
if (index < 0)
{
throw new HibasIndexKivetel();
}
else
{
T[] tmp = new T[tomb.Length * 2];
for (int i = 0; i < index; i++)
{
tmp[i] = tomb[i];
}
tmp[index] = ertek;
for (int i = index + 1; i < tomb.Length; i++)
{
tmp[i] = tomb[i - 1];
}
tomb = tmp;
n++;
}
}
public IEnumerator<T> GetEnumerator()
{
foreach (T t in tomb)
{
if (t != null)
{
yield return t;
}
}
}
public void Hozzafuz(T ertek)
{
if (n < tomb.Length)
{
tomb[n] = ertek;
n++;
}
else
{
T[] tmp = new T[tomb.Length * 2];
for (int i = 0; i < tomb.Length; i++)
{
tmp[i] = tomb[i];
}
tmp[n] = ertek;
tomb = tmp;
n++;
}
}
public T Kiolvas(int index)
{
if (index < 0 || index >= tomb.Length)
{
throw new HibasIndexKivetel();
}
return tomb[index];
}
public void Modosit(int index, T ertek)
{
if (index < 0 && index < tomb.Length)
{
throw new HibasIndexKivetel();
}
else
{
tomb[index] = ertek;
}
}
public void Torol(T ertek)
{
int m = n;
T[] tmp = new T[tomb.Length];
int index = 0;
for (int i = 0; i < m; i++)
{
if (ertek.Equals(tomb[i]))
{
n--;
continue;
}
tmp[index] = tomb[i];
index++;
}
tomb = tmp;
}
IEnumerator IEnumerable.GetEnumerator()
{
TombListaBejaro<T> bejaro = new TombListaBejaro<T>(tomb, n);
return bejaro;
}
}
public class TombListaBejaro<T> : IEnumerator<T>
{
T[] e;
int n;
int aktualisindex;
T current;
public T Current
{
get { return current; }
}
public TombListaBejaro(T[] e, int n)
{
this.n = n;
this.e = e;
aktualisindex = 0;
current = e[0];
}
object IEnumerator.Current => Current;
public void Dispose()
{
throw new NotImplementedException();
}
public bool MoveNext()
{
if (aktualisindex < n - 1)
{
aktualisindex++;
return true;
}
else
{
return false;
}
}
public void Reset()
{
aktualisindex = -1;
}
}
}

View File

@@ -4,5 +4,322 @@ using System.Collections.Generic;
namespace OE.ALGA.Adatszerkezetek
{
// 4. heti labor feladat - Tesztek: 04_LancoltImplementacioTesztek.cs
public class LancElem<T>
{
public T tart;
public LancElem<T>? kov;
public LancElem<T>? elozo;
public LancElem(T tart, LancElem<T>? kov, LancElem<T>? elozo)
{
this.tart = tart;
this.kov = kov;
this.elozo = elozo;
}
}
public class LancoltVerem<T> : Verem<T>
{
LancElem<T>? fej;
LancElem<T>? teteje;
public LancoltVerem()
{
}
public void Felszabadit()
{
}
public bool Ures
{
get { return fej == null; }
}
public T Felso()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
LancElem<T>? tmp = fej;
while (tmp.kov != null)
{
tmp = tmp.kov;
}
teteje = tmp;
return tmp.tart;
}
}
public void Verembe(T ertek)
{
if (Ures)
{
fej = new LancElem<T>(ertek, null, null);
teteje = fej;
}
else
{
teteje.kov = new LancElem<T>(ertek, null, teteje);
teteje = teteje.kov;
}
}
public T Verembol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
if (teteje.elozo == null)
{
T ertek = fej.tart;
fej = null;
teteje = fej;
return ertek;
}
else
{
T ertek = Felso();
teteje.elozo.kov = null;
teteje = teteje.elozo;
return ertek;
}
}
}
}
public class LancoltSor<T> : Sor<T>
{
LancElem<T>? fej;
LancElem<T>? vege;
public bool Ures
{
get { return (vege == null); }
}
public LancoltSor()
{
}
public void Felszabadit()
{
}
public T Elso()
{
return fej.tart;
}
public void Sorba(T ertek)
{
if (Ures)
{
fej = new LancElem<T>(ertek, null, null);
vege = fej;
}
else
{
LancElem<T>? tmp = fej;
while (tmp.kov != null)
{
tmp = tmp.kov;
}
tmp.kov = new LancElem<T>(ertek, null, tmp);
vege = tmp.kov;
}
}
public T Sorbol()
{
if (Ures)
{
throw new NincsElemKivetel();
}
else
{
if (vege.elozo == null)
{
T ertek = vege.tart;
vege = null;
return ertek;
}
else
{
T ertek = fej.tart;
fej = fej.kov;
fej.elozo = null;
return ertek;
}
}
}
}
public class LancoltLista<T> : Lista<T>, IEnumerable<T>
{
int n;
LancElem<T>? fej;
public int Elemszam
{
get { return n; }
}
public LancoltLista()
{
}
public void Felszabadit()
{
}
public void Bejar(Action<T> muvelet)
{
for (int i = 0; i < n; i++)
{
muvelet(Indexedik(i).tart);
}
}
public void Beszur(int index, T ertek)
{
if (fej == null)
{
if (index == 0)
{
Hozzafuz(ertek);
}
else
{
throw new HibasIndexKivetel();
}
}
else
{
if (index == 0)
{
fej.elozo = new LancElem<T>(ertek, fej, null);
fej = fej.elozo;
n++;
}
else if (index == n)
{
Hozzafuz(ertek);
n++;
}
else
{
LancElem<T>? xd = Indexedik(index).elozo;
xd.kov = new LancElem<T>(ertek, Indexedik(index), xd.kov);
xd.kov.kov.elozo = xd.kov;
n++;
}
}
}
public void Hozzafuz(T ertek)
{
if (Elemszam < 1)
{
fej = new LancElem<T>(ertek, null, null);
n++;
}
else
{
LancElem<T> asd = Indexedik(n - 1);
asd.kov = new LancElem<T>(ertek, null, asd);
n++;
}
}
public T Kiolvas(int index)
{
return Indexedik(index).tart;
}
public void Modosit(int index, T ertek)
{
Indexedik(index).tart = ertek;
}
public void Torol(T ertek)
{
LancElem<T> tmp = fej;
while (tmp.kov != null)
{
if (ertek.Equals(tmp.tart))
{
tmp.elozo.kov = tmp.kov;
tmp.kov.elozo = tmp.elozo;
}
tmp = tmp.kov;
}
}
private LancElem<T> Indexedik(int index)
{
LancElem<T>? tmp = fej;
for (int i = 0; i < index; i++)
{
tmp = tmp.kov;
}
return tmp;
}
public IEnumerator<T> GetEnumerator()
{
LancElem<T> tmp = fej;
while (tmp != null)
{
if (tmp.tart != null)
{
yield return tmp.tart;
}
tmp = tmp.kov;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
LancoltListaBejaro<T> bejaro = new LancoltListaBejaro<T>(this.fej);
return bejaro;
}
}
class LancoltListaBejaro<T> : IEnumerator<T>
{
LancElem<T> fej;
LancElem<T> aktualisElem;
public T Current
{
get { return aktualisElem.tart; }
}
object IEnumerator.Current => Current;
public LancoltListaBejaro(LancElem<T> fej)
{
this.fej = fej;
aktualisElem = fej;
}
public void Dispose()
{
throw new NotImplementedException();
}
public bool MoveNext()
{
if (aktualisElem.kov == null)
{
return false;
}
{
aktualisElem = aktualisElem.kov;
return true;
}
}
public void Reset()
{
aktualisElem = fej;
}
}
}

View File

@@ -1,6 +1,167 @@
using System;
using System.Drawing;
namespace OE.ALGA.Adatszerkezetek
namespace OE.ALGA;
internal class FaElem<T> where T : IComparable
{
// 5. heti labor feladat - Tesztek: 05_BinarisKeresoFaTesztek.cs
public T? tart;
public FaElem<T>? bal;
public FaElem<T>? jobb;
public FaElem(T? tart, FaElem<T>? bal, FaElem<T>? jobb)
{
this.tart = tart;
this.bal = bal;
this.jobb = jobb;
}
}
public class FaHalmaz<T> : Halmaz<T> where T : IComparable
{
FaElem<T>? gyoker;
private void BejarasPreOrder(FaElem<T> p, Action<T> muvelet)
{
if (p != null)
{
muvelet(p.tart);
BejarasPreOrder(p.bal, muvelet);
BejarasPreOrder(p.jobb, muvelet);
}
}
private void BejarasInOrder(FaElem<T> p, Action<T> muvelet)
{
if (p != null)
{
BejarasInOrder(p.bal, muvelet);
muvelet(p.tart);
BejarasInOrder(p.jobb, muvelet);
}
}
private void BejarasPostOrder(FaElem<T> p, Action<T> muvelet)
{
if (p != null)
{
BejarasPostOrder(p.bal, muvelet);
BejarasPostOrder(p.jobb, muvelet);
muvelet(p.tart);
}
}
public void Bejar(Action<T> muvelet)
{
BejarasPreOrder(gyoker, muvelet);
}
private static FaElem<T> ReszfabaBeszur(FaElem<T> p, T ertek)
{
if (p == null)
{
FaElem<T> uj = new FaElem<T>(ertek, null, null);
return uj;
}
else
{
if (p.tart.CompareTo(ertek) > 0)
{
p.bal = ReszfabaBeszur(p.bal, ertek);
}
else
{
if (p.tart.CompareTo(ertek) < 0)
{
p.jobb = ReszfabaBeszur(p.jobb, ertek);
}
}
return p;
}
}
public void Beszur(T ertek)
{
gyoker = ReszfabaBeszur(gyoker, ertek);
}
private static FaElem<T> ReszfaEleme(FaElem<T> p, T ertek)
{
FaElem<T>? tmp = null;
if (p == null)
{
return tmp;
}
else
{
if (p.tart.CompareTo(ertek) > 0)
{
tmp = ReszfaEleme(p.bal, ertek);
}
else if (p.tart.CompareTo(ertek) < 0)
{
tmp = ReszfaEleme(p.jobb, ertek);
}
else
{
tmp = p;
}
return tmp;
}
}
public bool Eleme(T ertek)
{
return (ReszfaEleme(gyoker, ertek) != null);
}
private static FaElem<T> KetGyerekesTorles(FaElem<T> p, T ertek)
{
if (p.jobb != null)
{
p.jobb = KetGyerekesTorles(p.jobb, ertek);
return p;
}
else
{
ertek = p.tart;
p = p.bal;
return p;
}
}
private static FaElem<T> ReszfabolTorol(ref FaElem<T> p, T ertek)
{
if (p == null)
{
throw new NincsElemKivetel();
}
if (p.tart.CompareTo(ertek) > 0)
{
p.bal = ReszfabolTorol(ref p.bal, ertek);
}
else if (p.tart.CompareTo(ertek) < 0)
{
p.jobb = ReszfabolTorol(ref p.jobb, ertek);
}
else
{
if (p.jobb == null && p.bal == null)
{
p = null;
}
else if (p.jobb == null && p.bal != null)
{
p = p.bal;
}
else if (p.jobb != null && p.bal == null)
{
p = p.jobb;
}
else
{
p = KetGyerekesTorles(p, p.tart);
}
}
return p;
}
public void Torol(T ertek)
{
if (gyoker != null)
{
ReszfabolTorol(ref gyoker, ertek);
}
}
}

102
ALGA/Product.cs Normal file
View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace OE.ALGA;
public class Product
{
[Validation(AttributeValidation.NotEmpty)]
public string Name { get; }
[Validation(AttributeValidation.PositiveNumber)]
public decimal Price { get; }
[Validation(AttributeValidation.NonNegative)]
public int Quantity { get; }
[Validation(AttributeValidation.FutureDate)]
public DateTime? Experiation { get; }
public Product(string name, decimal price, int quantity, DateTime? experiarion)
{
Name = name;
Price = price;
Quantity = quantity;
Experiation = experiarion;
}
}
public enum AttributeValidation
{
NotEmpty,
PositiveNumber,
NonNegative,
FutureDate
}
public class ValidationAttribute : Attribute
{
public AttributeValidation Rule { get; }
public ValidationAttribute(AttributeValidation rule)
{
Rule = rule;
}
}
public static class Validator
{
public static void Validate(Product product)
{
bool flag = false;
var t = product.GetType();
foreach (var p in t.GetProperties())
{
var value = p.GetValue(product);
switch (p.GetCustomAttribute<ValidationAttribute>().Rule)
{
case AttributeValidation.NotEmpty:
if (Convert.ToString(value) == "")
{
flag = true;
}
break;
case AttributeValidation.PositiveNumber:
if (Convert.ToInt32(value) <= 0)
{
flag = true;
}
break;
case AttributeValidation.NonNegative:
if (Convert.ToInt32(value) < 0)
{
flag = true;
}
break;
case AttributeValidation.FutureDate:
if (Convert.ToDateTime(value) < DateTime.Now)
{
flag = true;
}
break;
}
}
if (flag)
{
throw new WrongProductException();
}
else
{
Console.WriteLine("Product added successfuly");
}
}
}
public class WrongProductException : Exception
{
}

View File

@@ -1,125 +1,125 @@
//using NUnit.Framework;
//using OE.ALGA.Adatszerkezetek;
using NUnit.Framework;
using OE.ALGA.Adatszerkezetek;
//namespace OE.ALGA.Tesztek.Adatszerkezetek
//{
// [TestFixture(Category = "Adatszerkezetek", TestName = "05 - Fa Halmaz Tesztek")]
// public class FaHalmazTesztek
// {
// [TestCase]
// public void BeszurasUres()
// {
// Halmaz<string> v = new FaHalmaz<string>();
// v.Beszur("");
// Assert.Multiple(() =>
// {
// Assert.That(v.Eleme(""), Is.True);
// });
// }
// [TestCase]
// public void Beszuras()
// {
// Halmaz<int> v = new FaHalmaz<int>();
// v.Beszur(1);
// v.Beszur(3);
// v.Beszur(2);
// Assert.Multiple(() =>
// {
// Assert.That(v.Eleme(1), Is.True);
// Assert.That(v.Eleme(2), Is.True);
// Assert.That(v.Eleme(3), Is.True);
// });
// }
// [TestCase]
// public void DuplaBeszuras()
// {
// Halmaz<int> v = new FaHalmaz<int>();
// v.Beszur(1);
// v.Beszur(2);
// v.Beszur(3);
// v.Beszur(2);
// Assert.Multiple(() =>
// {
// Assert.That(v.Eleme(1), Is.True);
// Assert.That(v.Eleme(2), Is.True);
// Assert.That(v.Eleme(3), Is.True);
// });
// }
// [TestCase]
// public void Torles()
// {
// Halmaz<int> v = new FaHalmaz<int>();
// v.Beszur(1);
// v.Beszur(3);
// v.Beszur(2);
// v.Torol(2);
// Assert.Multiple(() =>
// {
// Assert.That(v.Eleme(1), Is.True);
// Assert.That(v.Eleme(2), Is.False);
// Assert.That(v.Eleme(3), Is.True);
// });
// }
// [TestCase]
// public void TorlesUres()
// {
// Halmaz<string> v = new FaHalmaz<string>();
// v.Beszur("");
// v.Beszur("1");
// v.Beszur("");
// v.Torol("");
// Assert.Multiple(() =>
// {
// Assert.That(v.Eleme(""), Is.False);
// Assert.That(v.Eleme("1"), Is.True);
// });
// }
// [TestCase]
// public void NemletezoTorles()
// {
// Halmaz<int> v = new FaHalmaz<int>();
// v.Beszur(1);
// v.Beszur(3);
// v.Beszur(2);
// Assert.Throws<NincsElemKivetel>(() => v.Torol(0));
// Assert.Multiple(() =>
// {
// Assert.That(v.Eleme(1), Is.True);
// Assert.That(v.Eleme(2), Is.True);
// Assert.That(v.Eleme(3), Is.True);
// });
// }
// [TestCase]
// public void DuplaTorles()
// {
// Halmaz<int> v = new FaHalmaz<int>();
// v.Beszur(1);
// v.Beszur(2);
// v.Beszur(3);
// v.Beszur(2);
// v.Torol(2);
// Assert.Multiple(() =>
// {
// Assert.That(v.Eleme(1), Is.True);
// Assert.That(v.Eleme(2), Is.False);
// Assert.That(v.Eleme(3), Is.True);
// Assert.That(v.Eleme(4), Is.False);
// });
// }
// [TestCase]
// public void PreorderBejaras()
// {
// Halmaz<int> v = new FaHalmaz<int>();
// v.Beszur(5);
// v.Beszur(3);
// v.Beszur(1);
// v.Beszur(8);
// v.Beszur(4);
// v.Beszur(9);
// v.Beszur(7);
// string osszefuzo = "";
// v.Bejar(x => osszefuzo += x);
// Assert.That(osszefuzo, Is.EqualTo("5314879"));
// }
// }
//}
namespace OE.ALGA.Tesztek.Adatszerkezetek
{
[TestFixture(Category = "Adatszerkezetek", TestName = "05 - Fa Halmaz Tesztek")]
public class FaHalmazTesztek
{
[TestCase]
public void BeszurasUres()
{
Halmaz<string> v = new FaHalmaz<string>();
v.Beszur("");
Assert.Multiple(() =>
{
Assert.That(v.Eleme(""), Is.True);
});
}
[TestCase]
public void Beszuras()
{
Halmaz<int> v = new FaHalmaz<int>();
v.Beszur(1);
v.Beszur(3);
v.Beszur(2);
Assert.Multiple(() =>
{
Assert.That(v.Eleme(1), Is.True);
Assert.That(v.Eleme(2), Is.True);
Assert.That(v.Eleme(3), Is.True);
});
}
[TestCase]
public void DuplaBeszuras()
{
Halmaz<int> v = new FaHalmaz<int>();
v.Beszur(1);
v.Beszur(2);
v.Beszur(3);
v.Beszur(2);
Assert.Multiple(() =>
{
Assert.That(v.Eleme(1), Is.True);
Assert.That(v.Eleme(2), Is.True);
Assert.That(v.Eleme(3), Is.True);
});
}
[TestCase]
public void Torles()
{
Halmaz<int> v = new FaHalmaz<int>();
v.Beszur(1);
v.Beszur(3);
v.Beszur(2);
v.Torol(2);
Assert.Multiple(() =>
{
Assert.That(v.Eleme(1), Is.True);
Assert.That(v.Eleme(2), Is.False);
Assert.That(v.Eleme(3), Is.True);
});
}
[TestCase]
public void TorlesUres()
{
Halmaz<string> v = new FaHalmaz<string>();
v.Beszur("");
v.Beszur("1");
v.Beszur("");
v.Torol("");
Assert.Multiple(() =>
{
Assert.That(v.Eleme(""), Is.False);
Assert.That(v.Eleme("1"), Is.True);
});
}
[TestCase]
public void NemletezoTorles()
{
Halmaz<int> v = new FaHalmaz<int>();
v.Beszur(1);
v.Beszur(3);
v.Beszur(2);
Assert.Throws<NincsElemKivetel>(() => v.Torol(0));
Assert.Multiple(() =>
{
Assert.That(v.Eleme(1), Is.True);
Assert.That(v.Eleme(2), Is.True);
Assert.That(v.Eleme(3), Is.True);
});
}
[TestCase]
public void DuplaTorles()
{
Halmaz<int> v = new FaHalmaz<int>();
v.Beszur(1);
v.Beszur(2);
v.Beszur(3);
v.Beszur(2);
v.Torol(2);
Assert.Multiple(() =>
{
Assert.That(v.Eleme(1), Is.True);
Assert.That(v.Eleme(2), Is.False);
Assert.That(v.Eleme(3), Is.True);
Assert.That(v.Eleme(4), Is.False);
});
}
[TestCase]
public void PreorderBejaras()
{
Halmaz<int> v = new FaHalmaz<int>();
v.Beszur(5);
v.Beszur(3);
v.Beszur(1);
v.Beszur(8);
v.Beszur(4);
v.Beszur(9);
v.Beszur(7);
string osszefuzo = "";
v.Bejar(x => osszefuzo += x);
Assert.That(osszefuzo, Is.EqualTo("5314879"));
}
}
}