vácuo confidencial button1_Click (remetente do objeto, EventArgs e)
{
LinkedList list1 = LinkedList novo ();
list1.AddFirst (“aa”);
list1.AddLast (“dd”);
list1.AddLast (“gg”);
list1.AddLast (“milímetro”);
list1.AddLast (“oo”);
list1.AddLast (“xx”);
LinkedList list2 = LinkedList novo ();
list2.AddFirst (“bb”);
list2.AddLast (“centímetro cúbico”);
list2.AddLast (“ff”);
list2.AddLast (“nn”);
list2.AddLast (“JJ”);
list2.AddLast (“zz”);
LinkedList fundiu = MergeSortedLists (list1, list2);
foreach (corda s no fundido)
{
System.Diagnostics.Debug.WriteLine;
}
}
LinkedList confidencial MergeSortedLists (LinkedList list1, LinkedList list2)
{
LinkedList fundiu = LinkedList novo ();
LinkedListNode nodeCurrent1 = list1.First;
LinkedListNode nodeCurrent2 = list2.First;
quando (! (&& nodeCurrent2==null de nodeCurrent1==null)){
se (zero do == nodeCurrent1)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
mais se (zero do == nodeCurrent2)
{
merged.AddLast (nodeCurrent1.Value);
nodeCurrent2 = nodeCurrent1.Next;
}
mais
{
comparisonResult = corda do int. Comparar (nodeCurrent1.Value, nodeCurrent2.Value);
se (comparisonResult < 0=""> 0)
{
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
mais
{as cordas de // são iguais
merged.AddLast (nodeCurrent1.Value);
nodeCurrent1 = nodeCurrent1.Next;
merged.AddLast (nodeCurrent2.Value);
nodeCurrent2 = nodeCurrent2.Next;
}
}
}
o retorno fundiu;
}
|