privé nietige button1_Click (objecten afzender, EventArgs e)
{
LinkedList list1 = nieuwe LinkedList ();
list1.AddFirst („aa“);
list1.AddLast („dd“);
list1.AddLast („gg“);
list1.AddLast („mm“);
list1.AddLast („oo“);
list1.AddLast („xx“);
LinkedList list2 = nieuwe LinkedList ();
list2.AddFirst („BB“);
list2.AddLast („CC“);
list2.AddLast („FF“);
list2.AddLast („nn“);
list2.AddLast („yy“);
list2.AddLast („zz“);
Samengevoegde LinkedList = MergeSortedLists (list1, list2);
foreach (koord s in samengevoegd)
{
System.Diagnostics.Debug.WriteLine;
}
}
privé LinkedList MergeSortedLists (LinkedList list1, LinkedList list2)
{
Samengevoegde LinkedList = nieuwe LinkedList ();
LinkedListNode nodeCurrent1 = list1.First;
LinkedListNode nodeCurrent2 = list2.First;
terwijl (! (nodeCurrent1==null && nodeCurrent2==null)){
als (ongeldige nodeCurrent1 ==)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
als anders (ongeldige nodeCurrent2 ==)
{
merged.AddLast (nodeCurrent1.Value);
nodeCurrent2 = nodeCurrent1.Next;
}
anders
{
int. comparisonResult = koord. Vergelijk (nodeCurrent1.Value, nodeCurrent2.Value);
als (comparisonResult < 0=""> 0)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
anders
{// de koorden zijn gelijk
merged.AddLast (nodeCurrent1.Value);
nodeCurrent1 = nodeCurrent1.Next;
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
}
}
samengevoegde terugkeer;
}
|