Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Zadanie4
- {
- public class Pair<T, U>
- {
- public Pair() {
- }
- public Pair(T first, U second) {
- this.First = first;
- this.Second = second;
- }
- public T First { get; set; }
- public U Second { get; set; }
- }
- public class Słownik<K,V>
- {
- private static int SIZE = 1000000;
- public int index;
- Pair<K,V>[] słownik = new Pair<K,V>[SIZE];
- public void Add (K key, V value)
- {
- Pair<K,V> para = new Pair<K,V>(key, value);
- słownik[index] = para;
- index += 1;
- }
- public void Search(K key)
- {
- for (int i = 0; i < index; i++)
- {
- if(object.Equals(słownik[i].First, key))
- {
- Console.WriteLine("{0}",słownik[i].Second);
- break;
- }
- }
- }
- public void Delete(K key)
- {
- int i = 0;
- int j = 0;
- int len = index - 1;
- Pair<K,V>[] słownik1 = new Pair<K,V>[SIZE];
- do
- {
- if(object.Equals(słownik[j].First,key))
- {
- j += 1;
- continue;
- }
- słownik1[i] = słownik[j];
- j += 1;
- i += 1;
- }
- while(i != len);
- index -= 1;
- słownik = słownik1;
- }
- public Słownik()
- {
- index = 0;
- }
- public void wypisz()
- {
- for(int i = 0; i < index; i++)
- {
- Console.WriteLine("klucz: {0}, wartość: {1}", słownik[i].First, słownik[i].Second);
- }
- }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- Słownik<string,int> dict = new Słownik<string,int>();
- dict.Add("Klucz1", 1);
- dict.Add("Klucz2", 2);
- dict.Add("Klucz3", 3);
- dict.Add("Klucz4", 4);
- dict.wypisz();
- dict.Search("Klucz2");
- dict.Delete("Klucz2");
- dict.wypisz();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement