privat utan laga kraft button1_Click (anmärka avsändaren, EventArgs e),
{
LinkedList list1 = nya LinkedList ();
list1.AddFirst (”aa”);
list1.AddLast (”dd”);
list1.AddLast (”gg”);
list1.AddLast (”en mm”);
list1.AddLast (”oo”);
list1.AddLast (”xx”);
LinkedList list2 = nya LinkedList ();
list2.AddFirst (”bb”);
list2.AddLast (”cc”);
list2.AddLast (”ff”);
list2.AddLast (”nn”);
list2.AddLast (”yy”);
list2.AddLast (”zz”);
LinkedList applicerade = MergeSortedLists (list1, list2);
foreach (stränga s, i applicerat),
{
System.Diagnostics.Debug.WriteLine;
}
}
privata LinkedList MergeSortedLists (LinkedList list1, LinkedList list2)
{
LinkedList applicerade = nya LinkedList ();
LinkedListNode nodeCurrent1 = list1.First;
LinkedListNode nodeCurrent2 = list2.First;
stunder (! (nodeCurrent1==null-&& nodeCurrent2==null)){
om (ogiltig == nodeCurrent1)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
annars, om (ogiltig == nodeCurrent2)
{
merged.AddLast (nodeCurrent1.Value);
nodeCurrent2 = nodeCurrent1.Next;
}
annars
{
int-comparisonResult = stränger. Jämför (nodeCurrent1.Value, nodeCurrent2.Value);
om (comparisonResult < 0=""> 0)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
annars
{// stränger är jämliket
merged.AddLast (nodeCurrent1.Value);
nodeCurrent1 = nodeCurrent1.Next;
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
}
}
retur applicerade;
}
|