Advertisement
Guest User

Untitled

a guest
May 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace HashTables
  9. {
  10.     public class Hashtables
  11.     {
  12.  
  13.         static int[] N = new int[] { 5000, 10000, 20000 };
  14.  
  15.         static void Main(String[] args)
  16.         {
  17.             Random rand = new Random();
  18.             //StreamReader r = new StreamReader(Hashtables.in);
  19.             for (int j = 0; (j < N.Length); j++)
  20.             {
  21.                 int[] key = new int[(N[j] / 2)];
  22.                 data_s[] da = new data_s[N[j]];
  23.                 for (int i = 0; (i
  24.                             < (N[j] / 2)); i++)
  25.                 {
  26.                     int kbef = ((int)((rand.Next(1, 100) * 100000)));
  27.                     int kaft = Hashtables.hash(kbef, N[j]);
  28.                     key[i] = kbef;
  29.                     while ((da[kaft] != null))
  30.                     {
  31.                         kaft++;
  32.                         if ((kaft == N[j]))
  33.                         {
  34.                             kaft = 0;
  35.                         }
  36.  
  37.                     }
  38.  
  39.                     da[kaft] = new data_s(kbef);
  40.                 }
  41.  
  42.                 int[] rrr = new int[N[j]];
  43.                 int k = N[j];
  44.                 for (int i = 0; (i
  45.                             < (N[j] / 2)); i++)
  46.                 {
  47.                     int kaft = Hashtables.hash(key[i], N[j]);
  48.                     while ((key[i] != da[kaft].L))
  49.                     {
  50.                         rrr[i]++;
  51.                         k++;
  52.                         kaft++;
  53.                         if ((kaft == N[j]))
  54.                         {
  55.                             kaft = 0;
  56.                         }
  57.  
  58.                     }
  59.  
  60.                 }
  61.  
  62.                 Console.WriteLine(("" + (N[j] + (")" + ((k * (1 / N[j])) + "")))));
  63.             }
  64.  
  65.         }
  66.  
  67.         public static int hash(int key, int N)
  68.         {
  69.             return (key % N);
  70.         }
  71.     }
  72.     class data_s
  73.     {
  74.  
  75.         public int L;
  76.  
  77.         public data_s(int data)
  78.         {
  79.             this.L = data;
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement