- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathHelpers.cs
49 lines (42 loc) · 1.58 KB
/
Helpers.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
usingSystem.Collections.Generic;
usingDataStructures.Lists;
namespaceAlgorithms.Common
{
publicstaticclassHelpers
{
/// <summary>
/// Swaps two values in an IList<T> collection given their indexes.
/// </summary>
publicstaticvoidSwap<T>(thisIList<T>list,intfirstIndex,intsecondIndex)
{
if(list.Count<2||firstIndex==secondIndex)//This check is not required but Partition function may make many calls so its for perf reason
return;
vartemp=list[firstIndex];
list[firstIndex]=list[secondIndex];
list[secondIndex]=temp;
}
/// <summary>
/// Swaps two values in an ArrayList<T> collection given their indexes.
/// </summary>
publicstaticvoidSwap<T>(thisArrayList<T>list,intfirstIndex,intsecondIndex)
{
if(list.Count<2||firstIndex==secondIndex)//This check is not required but Partition function may make many calls so its for perf reason
return;
vartemp=list[firstIndex];
list[firstIndex]=list[secondIndex];
list[secondIndex]=temp;
}
/// <summary>
/// Populates a collection with a specific value.
/// </summary>
publicstaticvoidPopulate<T>(thisIList<T>collection,Tvalue)
{
if(collection==null)
return;
for(inti=0;i<collection.Count;i++)
{
collection[i]=value;
}
}
}
}