本文整理汇总了C#中LinkedListNode.Add方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedListNode.Add方法的具体用法?C# LinkedListNode.Add怎么用?C# LinkedListNode.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedListNode
的用法示例。
在下文中一共展示了LinkedListNode.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOnesFirst
public static LinkedListNode<int> AddOnesFirst(LinkedListNode<int> a, LinkedListNode<int> b, int numBase = _DEFAULT_BASE)
{
var ret = new LinkedListNode<int>();
int remainder = 0;
while (a != null || b != null)
{
var val = remainder;
if (a != null)
{
val += a.Value;
}
if (b != null)
{
val += b.Value;
}
remainder = val / numBase;
val = val % numBase;
ret.Add(val);
a = a?.Next;
b = b?.Next;
}
if (remainder > 0)
{
ret.Add(remainder);
}
return ret;
}
示例2: AddOnesLast
public static LinkedListNode<int> AddOnesLast(LinkedListNode<int> a, LinkedListNode<int> b, int numBase = _DEFAULT_BASE)
{
var recurseRet = AddOnesLastRecursive(a, b, numBase);
LinkedListNode<int> ret;
if(recurseRet.Item1 != 0)
{
ret = new LinkedListNode<int>(recurseRet.Item1);
ret.Add(recurseRet.Item2);
}
else
{
ret = recurseRet.Item2;
}
return ret;
}
示例3: AddOnesLastRecursive
private static Tuple<int, LinkedListNode<int>> AddOnesLastRecursive(LinkedListNode<int> a, LinkedListNode<int> b, int numBase)
{
int remainder = 0;
int value = 0;
LinkedListNode<int> aNext = null, bNext = null;
if(a == null && b == null)
{
return null;
}
else if(b == null || a.Length > b.Length)
{
value = a.Value;
aNext = a.Next;
bNext = b;
}
else if(a == null || b.Length > a.Length)
{
value = b.Value;
aNext = a;
bNext = b.Next;
}
else
{
value = a.Value + b.Value;
remainder = value / numBase;
value = value % numBase;
aNext = a.Next;
bNext = b.Next;
}
var ret = new LinkedListNode<int>(value);
var nextRet = AddOnesLastRecursive(aNext, bNext, numBase);
if (nextRet != null)
{
ret.Value += nextRet.Item1;
remainder += ret.Value / numBase;
ret.Value = ret.Value % numBase;
ret.Add(nextRet.Item2);
}
return Tuple.Create(remainder, ret);
}