-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecList.cs
More file actions
62 lines (54 loc) · 1.37 KB
/
RecList.cs
File metadata and controls
62 lines (54 loc) · 1.37 KB
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
using System;
using System.Collections.Generic;
namespace NSProgram
{
public class ERec
{
public int games = 1;
public string move =string.Empty;
}
public class RecList:List<ERec>
{
public int FindRec(ERec r)
{
int first = -1;
int last = Count;
while (true)
{
if (last - first == 1)
return last;
int middle = (first + last) >> 1;
ERec rec = this[middle];
if(String.Compare(r.move,rec.move, comparisonType: StringComparison.OrdinalIgnoreCase)<=0)
last = middle;
else
first = middle;
}
}
public bool AddRec(ERec rec)
{
int index = FindRec(rec);
if (index == Count)
Add(rec);
else
{
ERec r = this[index];
if (r.move == rec.move)
{
this[index].games++;
return false;
}
else
Insert(index, rec);
}
return true;
}
public void SortGames()
{
Sort(delegate (ERec r1, ERec r2)
{
return r2.games - r1.games;
});
}
}
}