[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace ConsoleApplication4
{
Class Program
{
Static void Display (empty list <string> ls)
{
Foreach (string s in ls)
{
Console. WriteLine (s );
}
}
Static void MergeList (sorted list <string> ls1, sorted list <string> ls2, ref sorted list <string> ls3)
{
Required listnode <string> p1 = ls1.First;
Required listnode <string> p2 = ls2.First;
Inclulistnode <string> p3 = new inclulistnode <string> ("");
If (p1.Value. CompareTo (p2.Value) <0)
{
P3.Value = p1.Value;
P1 = p1.Next;
}
Else
{
P3.Value = p2.Value;
P2 = p2.Next;
}
Ls3.AddFirst (p3 );
While (p1! = Null) & (p2! = Null ))
{
Required listnode <string> p4 = new required listnode <string> ("");
If (p1.Value. CompareTo (p2.Value) <0)
{
P4.Value = p1.Value;
Ls3.AddLast (p4 );
P1 = p1.Next;
}
Else
{
P4.Value = p2.Value;
Ls3.AddLast (p4 );
P2 = p2.Next;
}
}
While (p1! = Null)
{
Inclulistnode <string> p5 = new inclulistnode <string> ("");
P5.Value = p1.Value;
Ls3.AddLast (p5 );
P1 = p1.Next;
}
While (p2! = Null)
{
Inclulistnode <string> p6 = new inclulistnode <string> ("");
P6.Value = p2.Value;
Ls3.AddLast (p6 );
P2 = p2.Next;
}
}
Static void Main (string [] args)
{
String [] words1 = {"aa", "bb", "cc", "cd1 "};
Shortlist <string> ls1 = new shortlist <string> (words1 );
String [] words2 = {"aa1", "bb3", "ee", "xx "};
Shortlist <string> ls2 = new shortlist <string> (words2 );
Shortlist <string> ls3 = new shortlist <string> ();
MergeList (ls1, ls2, ref ls3 );
Display (ls3 );
Console. ReadKey ();
}
}
}
Author: weishanshan00