Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _2018_12_07_GenerickySeznam.Model
- {
- class GenerickySeznam<T>:IEnumerable<T>
- {
- Node<T> zac = null, kon = null;
- public void VlozNaPozici(T vstup, int kam)
- {
- }
- public bool OdeberHodnotu(T co)
- {
- return true;
- }
- public void Vloz(T vstup)
- {
- Node<T> novy = new Node<T>(vstup);
- if (zac == null)
- {
- kon = zac = novy;
- }
- kon.dalsi = novy;
- novy.dalsi = null;
- kon = novy;
- }
- public T Odeber()
- {
- T docasny = zac.hodnota;
- zac = zac.dalsi;
- if (zac == null) kon = null;
- return docasny;
- }
- public static GenerickySeznam<T> operator +(GenerickySeznam<T> prvni, GenerickySeznam<T> druhy)
- {
- GenerickySeznam<T> novy = new GenerickySeznam<T>();
- //vytvoříme nový seznam, do kterého zkopírujeme prvni a druhy
- return novy;
- }
- public static GenerickySeznam<T> operator +(GenerickySeznam<T> prvni, T druhy)
- {
- GenerickySeznam<T> novy = new GenerickySeznam<T>();
- //vytvoříme kopii existujícího seznamu (prvni) a vlozime do nej druhy
- return novy;
- }
- public IEnumerator<T> GetEnumerator()
- {
- var node = zac;
- while (node != null)
- {
- yield return node.hodnota;
- node = node.dalsi;
- }
- }
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- internal class Node<T>
- {
- public T hodnota;
- public Node<T> dalsi;
- public Node(T hodn)
- {
- hodnota = hodn;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement