-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyDictionary.cs
44 lines (42 loc) · 1.05 KB
/
MyDictionary.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
using System;
using System.Collections.Generic;
using System.Text;
namespace MyDictionary
{
class MyDictionary<Tvalue,Tkey>
{
Tvalue[] tvalues;
Tkey[] tkeys;
public MyDictionary()
{
tvalues = new Tvalue [0] ;
tkeys = new Tkey[0];
}
public void Add(Tvalue value, Tkey key)
{
Tvalue[] tempVal = tvalues;
Tkey[] tempKey = tkeys;
tvalues = new Tvalue[tvalues.Length + 1];
tkeys = new Tkey[tkeys.Length + 1];
for (int i = 0; i < tempVal.Length; i++)
{
tvalues[i] = tempVal[i];
tkeys[i] = tempKey[i];
}
tvalues[tvalues.Length - 1] = value;
tkeys[tkeys.Length - 1] = key;
}
public int Lenght
{
get { return tkeys.Length; }
}
public Tkey[] Keys
{
get { return tkeys; }
}
public Tvalue[] Values
{
get { return tvalues; }
}
}
}