public void Delete(K key) { if (key.CompareTo(this.next.key) == 0) { Console.WriteLine("Usuwany element - {0}", this.next.key); this.next = this.next.next; } else if (this.next != null) { this.next.Delete(key); } }
public void Add(K key, V val) { if (this.next != null) { this.next.Add(key, val); } else { this.next = new slownik <K, V>(); this.next.key = key; this.next.val = val; } }
public void Delete(K key) { if (key.CompareTo(this.next.key) == 0) //jesli jest taki sam (znalezlismy), > 0 po this w porzadku, < 0 przed this w porzadku { Console.WriteLine("Usuwamy element - " + this.next.key); this.next = this.next.next; //przsuwamy wskaznik dalej } else { if (this.next != null) //uważać żeby nie wyleciec poza koniec slownika { this.next.Delete(key); } } }
public V Find(K key) { slownik <K, V> current = this; while (key.CompareTo(current.key) != 0) { Console.WriteLine("sprawdzany klucz - {0}", current.key); current = current.next; if (current == null) { return(default(V)); } } Console.WriteLine("Znaleziony klucz - {0}", current.key); return(current.value); }
static void Main(string[] args) { var Dictionary = new slownik <int, string>(); Dictionary.Add(13, "marcin"); Dictionary.Add(2, "magda"); Dictionary.Add(32, "dawid"); Dictionary.Print(); Dictionary.Delete(13); Dictionary.Find(13); Dictionary.Find(32); Console.ReadKey(); }
public V Find(K key) { slownik <K, V> current = this; while (key.CompareTo(current.key) != 0) { Console.WriteLine("Sprawdzany klucz - " + current.key); current = current.next; if (current == null) { Console.WriteLine("Nie znaleziono podanego klucza"); Console.WriteLine(); return(default(V)); } } Console.WriteLine("Znaleziony klucz - " + current.key); Console.WriteLine(); return(current.val); }
public slownik() { next = null; key = default(K); val = default(V); }