-
Notifications
You must be signed in to change notification settings - Fork 0
/
Finder.cs
62 lines (55 loc) · 1.46 KB
/
Finder.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
using System.Collections.Generic;
namespace Algorithm
{
public class Finder
{
private readonly List<Thing> _p;
public Finder(List<Thing> p)
{
_p = p;
}
public F Find(FT ft)
{
var tr = new List<F>(); ;
for(var i = 0; i < _p.Count - 1; i++)
{
for(var j = i + 1; j < _p.Count; j++)
{
var r = new F();
if(_p[i].X < _p[j].X)
{
r.P1 = _p[i];
r.P2 = _p[j];
}
else
{
r.P1 = _p[j];
r.P2 = _p[i];
}
r.D = r.P2.X - r.P1.X;
tr.Add(r);
}
}
F answer = tr[0];
foreach(var result in tr)
{
switch(ft)
{
case FT.One:
if(result.D < answer.D)
{
answer = result;
}
break;
case FT.Two:
if(result.D > answer.D)
{
answer = result;
}
break;
}
}
return answer;
}
}
}