Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- 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; }
- };
- namespace Zad_2
- {
- class Slownik
- {
- private static int SIZE = 1000000;
- int[] Kluczory = new int[SIZE];
- string[] Wartosci = new string[SIZE];
- private int index = 0;
- public void Dodaj(int a, string b)
- {
- Kluczory[index] = a;
- Wartosci[index] = b;
- index++;
- }
- public string Znajdz(int klucz)
- {
- for (int i = 0; i < index; i++)
- {
- if (klucz == Kluczory[i]) return Wartosci[i - 1];
- }
- return "Nie znaleziono ;c \n";
- }
- void Scal()
- {
- for (int i = 0; i < index; i++)
- {
- if(Kluczory[i] == 0)
- {
- Kluczory[i] = Kluczory[i + 1];
- Wartosci[i] = Wartosci[i + 1];
- Kluczory[i + 1] = 0;
- Wartosci[i + 1] = "";
- }
- }
- }
- public void Usun(int klucz)
- {
- for (int i = 0; i < index; i++)
- {
- if (klucz == Kluczory[i])
- {
- Kluczory[i] = 0;
- Wartosci[i] = "";
- return;
- }
- }
- Scal();
- index--;
- }
- public void Wypisz()
- {
- for (int i = 0; i < index; i++)
- {
- if(Kluczory[i] != 0)Console.WriteLine(Kluczory[i] + " " + Wartosci[i]);
- }
- }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- Slownik slowniczor = new Slownik();
- slowniczor.Dodaj(1,"Polska");
- slowniczor.Dodaj(2, "Anglia");
- slowniczor.Dodaj(3, "Niemcy");
- slowniczor.Dodaj(4, "Rosja");
- slowniczor.Dodaj(5, "Ukraina");
- slowniczor.Wypisz();
- Console.WriteLine("\n\nTeraz znajdziemy sobie Niemcy : ");
- Console.WriteLine("Znalazlem : " + slowniczor.Znajdz(4));
- Console.WriteLine("\n\nTeraz usuniemy rosje i wypiszemy wszystko : ");
- slowniczor.Usun(4);
- slowniczor.Wypisz();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement