Advertisement
Febrin

PO Slownik

Mar 10th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. using System;
  2.  
  3. public class Pair<T, U>
  4. {
  5.     public Pair()
  6.     {
  7.     }
  8.  
  9.     public Pair(T first, U second)
  10.     {
  11.         this.First = first;
  12.         this.Second = second;
  13.     }
  14.  
  15.     public T First { get; set; }
  16.     public U Second { get; set; }
  17. };
  18.  
  19. namespace Zad_2
  20. {
  21.     class Slownik
  22.     {
  23.         private static int SIZE = 1000000;
  24.         int[] Kluczory = new int[SIZE];
  25.         string[] Wartosci = new string[SIZE];
  26.  
  27.         private int index = 0;
  28.  
  29.  
  30.         public void Dodaj(int a, string b)
  31.         {
  32.             Kluczory[index] = a;
  33.             Wartosci[index] = b;
  34.             index++;
  35.         }
  36.  
  37.         public string Znajdz(int klucz)
  38.         {
  39.             for (int i = 0; i < index; i++)
  40.             {
  41.                 if (klucz == Kluczory[i]) return Wartosci[i - 1];
  42.             }
  43.             return "Nie znaleziono ;c \n";
  44.         }
  45.  
  46.         void Scal()
  47.         {
  48.             for (int i = 0; i < index; i++)
  49.             {
  50.                 if(Kluczory[i] == 0)
  51.                 {
  52.                     Kluczory[i] = Kluczory[i + 1];
  53.                     Wartosci[i] = Wartosci[i + 1];
  54.  
  55.                     Kluczory[i + 1] = 0;
  56.                     Wartosci[i + 1] = "";
  57.                 }
  58.             }
  59.         }
  60.  
  61.         public void Usun(int klucz)
  62.         {
  63.             for (int i = 0; i < index; i++)
  64.             {
  65.                 if (klucz == Kluczory[i])
  66.                 {
  67.                     Kluczory[i] = 0;
  68.                     Wartosci[i] = "";
  69.                     return;
  70.                 }
  71.             }
  72.  
  73.             Scal();
  74.             index--;
  75.  
  76.         }
  77.  
  78.         public void Wypisz()
  79.         {
  80.             for (int i = 0; i < index; i++)
  81.             {
  82.                 if(Kluczory[i] != 0)Console.WriteLine(Kluczory[i] + "  " + Wartosci[i]);
  83.             }
  84.         }
  85.  
  86.      
  87.     }
  88.  
  89.     class MainClass
  90.     {
  91.         public static void Main(string[] args)
  92.         {
  93.  
  94.             Console.WriteLine("Hello World!");
  95.  
  96.             Slownik slowniczor = new Slownik();
  97.             slowniczor.Dodaj(1,"Polska");
  98.             slowniczor.Dodaj(2, "Anglia");
  99.             slowniczor.Dodaj(3, "Niemcy");
  100.             slowniczor.Dodaj(4, "Rosja");
  101.             slowniczor.Dodaj(5, "Ukraina");
  102.  
  103.             slowniczor.Wypisz();
  104.             Console.WriteLine("\n\nTeraz znajdziemy sobie Niemcy : ");
  105.             Console.WriteLine("Znalazlem : " + slowniczor.Znajdz(4));
  106.  
  107.             Console.WriteLine("\n\nTeraz usuniemy rosje i wypiszemy wszystko : ");
  108.             slowniczor.Usun(4);
  109.             slowniczor.Wypisz();
  110.  
  111.            
  112.        
  113.  
  114.  
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement