本文整理汇总了C#中IComparable类的典型用法代码示例。如果您正苦于以下问题:C# IComparable类的具体用法?C# IComparable怎么用?C# IComparable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IComparable类属于命名空间,在下文中一共展示了IComparable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Field
public Field(XmlElement elField)
{
String typeName = elField.GetAttribute("type");
string lbStr = elField.GetAttribute("lower-bound");
string ubStr = elField.GetAttribute("upper-bound");
string fieldTypeStr = elField.GetAttribute("fieldtype");
string valueStr = elField.InnerText;
type = ClassTypes.GetType(typeName);
fieldType = ParseTypeString(fieldTypeStr);
if (!Formal)
{
value = ParseFieldValue(type, valueStr);
}
else
{
if (lbStr != null)
{
lowerBound = (IComparable) ParseFieldValue(type, lbStr);
}
if (ubStr != null)
{
upperBound = (IComparable) ParseFieldValue(type, ubStr);
}
}
}
示例2: Sort
public override void Sort(IComparable[] a)
{
int n = a.Length;
int h = 1;
int arrayLength = 1;
while (h < n / 3)
{
h = h * 3 + 1;
arrayLength++;
}
int[] hmas = new int[arrayLength--];
hmas[arrayLength--] = h;
h = h / 3;
while (h >= 1)
{
hmas[arrayLength--] = h;
h = h / 3;
}
for (int k = hmas.Length - 1; k >= 0; k--)
{
for (int i = hmas[k]; i < n; i++)
{
for (int j = i; j > 0 && less(a[j], a[j - 1]); j -= h)
{
exch(a, j, j - 1);
}
}
}
}
示例3: DevideCommand_Test
public void DevideCommand_Test()
{
var inputStringCommand = new[]
{
"5 5\r\n1 2 N\r\nLMLMLMLMM\r\n",
"5 5\r\n1 2 N\r\nLMLMLMLMM\r\n1 2 N"
};
var outputValues = new IComparable[]
{
3,
"ERROR"
};
for (int i = 0; i < inputStringCommand.Length; i++)
{
try
{
DevideCommand devideCommand = new DevideCommand(inputStringCommand[i]);
Assert.AreEqual(devideCommand.GetArrayListCommand.Length, outputValues[i]);
}
catch (DevideCommandException exceptionDevideCommand)
{
Assert.AreEqual(exceptionDevideCommand.Message, "Не достаточно данных для отправки");
}
}
}
示例4: XIntervalSeries
public XIntervalSeries(IComparable key, bool autoSort, bool allowDuplicateXValues)
{
int num1 = autoSort ? 1 : 0;
int num2 = allowDuplicateXValues ? 1 : 0;
// ISSUE: explicit constructor call
base.\u002Ector(key, num1 != 0, num2 != 0);
}
示例5: Insert
/// <summary> Insert into the tree. Does nothing if item already present.
/// </summary>
/// <param name="item">the item to insert.
/// </param>
public virtual void Insert(IComparable item)
{
current = parent = grand = header;
nullNode.element = item;
while (current.element.CompareTo(item) != 0)
{
great = grand; grand = parent; parent = current;
current = item.CompareTo(current.element) < 0?current.left:current.right;
// Check if two red children; fix if so
if (current.left.color == RED && current.right.color == RED)
handleReorient(item);
}
// Insertion fails if already present
if (current != nullNode)
return ;
current = new RedBlackNode(item, nullNode, nullNode);
// Attach to parent
if (item.CompareTo(parent.element) < 0)
parent.left = current;
else
parent.right = current;
handleReorient(item);
}
示例6: Search
public virtual IList Search(IComparable key)
{
var positionOfKey = GetPositionOfKey(key);
var keyIsHere = positionOfKey > 0;
int realPosition;
if (keyIsHere)
{
realPosition = positionOfKey - 1;
var valueAsList = GetValueAt(realPosition);
return valueAsList;
}
if (IsLeaf())
{
// key is not here and node is leaf
return null;
}
realPosition = -positionOfKey - 1;
var node = (IBTreeNodeMultipleValuesPerKey) GetChildAt(realPosition, true);
return node.Search(key);
}
示例7: DoMerge
public void DoMerge(IComparable[] numbers, int left, int mid, int right)
{
IComparable[] temp = new IComparable[arraySize];
int i, left_end, num_elements, tmp_pos;
left_end = (mid - 1);
tmp_pos = left;
num_elements = (right - left + 1);
while ((left <= left_end) && (mid <= right))
{
if (numbers[left].CompareTo(numbers[mid]) <= 0)
temp[tmp_pos++] = numbers[left++];
else
temp[tmp_pos++] = numbers[mid++];
}
while (left <= left_end)
temp[tmp_pos++] = numbers[left++];
while (mid <= right)
temp[tmp_pos++] = numbers[mid++];
for (i = 0; i < num_elements; i++)
{
numbers[right] = temp[right];
right--;
}
}
示例8: IsGreaterOrEqual
/// <summary>
/// Indicates whether the instance is greater or equal to the reference value.
/// </summary>
/// <param name="value">The instance to test.</param>
/// <param name="referenceValue">The reference value to test.</param>
/// <returns><strong>true</strong> if the instance is greater or equal to the reference
/// value; otherwise, <strong>false</strong>.</returns>
/// <exception cref="ArgumentNullException"><em>value</em> or <em>referenceValue</em> is
/// <strong>null</strong>.</exception>
public static bool IsGreaterOrEqual(this IComparable value, IComparable referenceValue)
{
Precondition.IsNotNull(value, nameof(value));
Precondition.IsNotNull(referenceValue, nameof(referenceValue));
return value.IsGreater(referenceValue) || value.IsEqual(referenceValue);
}
示例9: enqueue
public void enqueue(IComparable item)
{
if (lastIndex == maxIndex)
throw new Exception("Priority queue is full");
lastIndex = lastIndex + 1;
reheapUp(item);
}
示例10: GetValues
protected override IEnumerable<long> GetValues(ISonesIndex myIndex, IComparable myIComparable)
{
if (myIndex is ISonesRangeIndex)
{
//use the range funtionality
foreach (var aVertexID in ((ISonesRangeIndex)myIndex).LowerThan(myIComparable, true))
{
yield return aVertexID;
}
}
else
{
//stupid, but works
foreach (var aVertexIDSet in myIndex.Keys().Where(key => key.CompareTo(myIComparable) <= 0).Select(key => myIndex[key]))
{
foreach (var aVertexID in aVertexIDSet)
{
yield return aVertexID;
}
}
}
yield break;
}
示例11: IsGreater
/// <summary>
/// Indicates whether the instance is greater as the reference value.
/// </summary>
/// <param name="value">The instance to test.</param>
/// <param name="referenceValue">The reference value to test.</param>
/// <returns><strong>true</strong> if the instance is greater as the reference value;
/// otherwise, <strong>false</strong>.</returns>
/// <exception cref="ArgumentNullException"><em>value</em> or <em>referenceValue</em> is
/// <strong>null</strong>.</exception>
public static bool IsGreater(this IComparable value, IComparable referenceValue)
{
Precondition.IsNotNull(value, nameof(value));
Precondition.IsNotNull(referenceValue, nameof(referenceValue));
return value.CompareTo(referenceValue) == 1;
}
示例12: Quicksort
public static void Quicksort(IComparable[] elements, int left, int right)
{
int leftIndex = left, rightIndex = right;
IComparable pivot = elements[(left + right) / 2];
while (leftIndex <= rightIndex)
{
while (elements[leftIndex].CompareTo(pivot) < 0)
{
leftIndex++;
}
while (elements[rightIndex].CompareTo(pivot) > 0)
{
rightIndex--;
}
if (leftIndex <= rightIndex)
{
IComparable temp = elements[leftIndex];
elements[leftIndex] = elements[rightIndex];
elements[rightIndex] = temp;
leftIndex++;
rightIndex--;
}
}
if (left < rightIndex)
{
Quicksort(elements, left, rightIndex);
}
if (leftIndex < right)
{
Quicksort(elements, leftIndex, right);
}
}
示例13: ArgumentInRange
public static void ArgumentInRange(IComparable argument, IComparable minimum, IComparable maximum, string paramName = DefaultParamName)
{
if (argument.CompareTo(minimum) < 0 || argument.CompareTo(maximum) > 0)
{
throw new ArgumentException(string.Format("{0} must be between {1} and {2}.", paramName, minimum, maximum), paramName);
}
}
示例14: ArgumentAtMost
public static void ArgumentAtMost(IComparable argument, IComparable maximum, string paramName = DefaultParamName)
{
if (argument.CompareTo(maximum) > 0)
{
throw new ArgumentException(string.Format("{0} must be at most {1}.", paramName, maximum), paramName);
}
}
示例15: Partition_Version_One
private int Partition_Version_One(IComparable[] a, int lo, int hi)
{
int i = lo;
int j = hi + 1;
IComparable value = a[lo];
while (true)
{
while (Less(a[++i], value))
{
if (i == hi) break;
}
while (Less(value, a[--j]))
{
if (j == lo) break;
}
if (i >= j)
{
break;
}
Exchange(a, i, j);
}
Exchange(a, lo, j);
return j;
}