private Lücke button1_Click (Gegenstandabsender, EventArgs e)
{
LinkedList list1 = neues LinkedList ();
list1.AddFirst („AA“);
list1.AddLast („DD“);
list1.AddLast („GG“);
list1.AddLast („Millimeter“);
list1.AddLast („oo“);
list1.AddLast („xx“);
LinkedList list2 = neues LinkedList ();
list2.AddFirst („Bb“);
list2.AddLast („cm“);
list2.AddLast („FF“);
list2.AddLast („nn“);
list2.AddLast („JJ“);
list2.AddLast („zz“);
LinkedList vermischte = MergeSortedLists (list1, list2);
foreach (Schnur s, in vermischt)
{
System.Diagnostics.Debug.WriteLine;
}
}
privates LinkedList MergeSortedLists (LinkedList list1, LinkedList list2)
{
LinkedList vermischte = neues LinkedList ();
LinkedListNode nodeCurrent1 = list1.First;
LinkedListNode nodeCurrent2 = list2.First;
während (! (nodeCurrent1==null && nodeCurrent2==null)){
wenn (== nodeCurrent1 Null)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
sonst, wenn (== nodeCurrent2 Null)
{
merged.AddLast (nodeCurrent1.Value);
nodeCurrent2 = nodeCurrent1.Next;
}
sonst
{
int-comparisonResult = Schnur. Vergleichen (nodeCurrent1.Value, nodeCurrent2.Value);
wenn (comparisonResult < 0=""> 0)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
sonst
{//-Schnüre sind gleich
merged.AddLast (nodeCurrent1.Value);
nodeCurrent1 = nodeCurrent1.Next;
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
}
}
Rückkehr vermischte;
}
|