-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class1.cs
120 lines (108 loc) · 3.56 KB
/
Class1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSA
{
class HashTable
{
class HashEntry
{
private int key;
private string value;
public HashEntry(int key, string value)
{
this.key = key;
this.value = value;
}
public int GetKey()
{
return key;
}
public string GetValue()
{
return value;
}
}
public class HashTableUsingArray
{
private int size = 128;
HashEntry[] newHashTable;
public HashTableUsingArray()
{
newHashTable = new HashEntry[size];
for(int i =0; i<size; i++)
{
newHashTable[i] = null;
}
}
public string Get(int key)
{
int hash = key%size;
while(newHashTable[hash] != null && newHashTable[hash].GetKey() != key)
{
hash = (hash + 1) % size + 10 % 3;
}
if(newHashTable[hash].GetKey() == key)
{
return newHashTable[hash].GetValue();
}
else {
return "Key not found";
}
}
public void Put(int key, string value)
{
int hash = key%size;
while(newHashTable[hash] != null && newHashTable[hash].GetKey() != key)
{
hash = (hash+1)%size;
}
newHashTable[hash] = new HashEntry(key, value);
}
}
public static void ImplementHashTableinCSharp()
{
Dictionary<string, int> EmployeeID = new Dictionary<string, int>();
EmployeeID.Add("Susan", 24);
EmployeeID.Add("Robert", 42);
EmployeeID.Add("Abhinav", 26);
EmployeeID.Add("Amith", 24);
EmployeeID.Add("Mukul", 22);
int getAge =0;
if(EmployeeID.TryGetValue("Susan", out getAge))
{
Console.WriteLine("The age of the given emplyee is :" + getAge);
}
foreach(var match in EmployeeID)
{
if(match.Value<35 )
Console.WriteLine("\n The key is : " + match.Key + " & the value is : " + match.Value);
}
}
public static string ReverseString(string Str)
{
char[] StrCh= Str.ToCharArray();
for (int i = 0; i < StrCh.Length/2; i++)
{
char c = StrCh[i];
StrCh[i] = StrCh[Str.Length - 1 - i];
StrCh[Str.Length - 1 - i] = c;
}
Console.WriteLine(StrCh);
return StrCh.ToString();
}
public static void PrintTables()
{
for (int i =1;i<13;i++)
{
for(int j =1;j<13;j++)
{
Console.Write("\t"+i * j);
}
Console.WriteLine("\n ");
}
}
}
}