11
if (previous != null)
{
previous.Next = current.Next; if (current == last)
last = previous;
}
else
{
if (count == 1)
{
first = last = null;
}
else
{
first = current.Next; last.Next = current.Next;
}
}
count--; return true;
}
previous = current; current = current.Next;
} while (current != first);
return false;
}
public bool IsEmpty { get { return count == 0; } } public void Clear()
{
first = null; last = null; count = 0;
}
public int Count { get { return count; } } public bool Contains(T data)
{
Node<T> current = first;
if (current == null) return false; do
{
if (current.Data.Equals(data)) return true;
current = current.Next;
}
while (current != first); return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)this).GetEnumerator();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
12
{
Node<T> current = first; do
{
if (current != null)
{
yield return current.Data; current = current.Next;
}
}
while (current != first);
}
}
}
class Program
{
static void Change(ref int p1, ref int p2)
{
var temp = p1; p1 = p2;
p2 = temp;
}
static int[] Sort(int[] array)
{
var d = array.Length / 2; while (d >= 1)
{
for (var i = d; i < array.Length; i++)
{
var j = i;
while ((j >= d) && (array[j - d] > array[j]))
{
Change(ref array[j], ref array[j - d]); j = j - d;
}
}
d = d / 2;
}
return array;
}
static void Main(string[] args)
{
sd3.LinkedList<int> List_1 = new sd3.LinkedList<int>(); sd3.LinkedList<int> List_2 = new sd3.LinkedList<int>();
var rand = new Random(); int[] vvod1 = new int[15]; int[] vvod2 = new int[15];
for (int i = 0; i < vvod1.Length; i++)
{
vvod1[i] = rand.Next(1, 500); vvod2[i] = rand.Next(1, 500);
}
foreach (var item in vvod1)
{
13
List_1.Add(item);
}
foreach (var item in vvod2)
{
List_2.Add(item);
}
foreach (var item in List_1)
{
Console.WriteLine(item);
}
Console.WriteLine("\n"); foreach (var item in List_2)
{
Console.WriteLine(item);
}
Sum(List_1, List_2);
Console.WriteLine("\n После операций: \n"); foreach (var item in List_2)
{
Console.WriteLine(item);
}
}
static void Sum(sd3.LinkedList<int> List_1, sd3.LinkedList<int> List_2)
{
foreach (var item in List_1)
{
List_2.Add(item);
}
int[] f = new int[List_2.Count]; int k = 0;
foreach (var item in List_2)
{
f[k] = item; k++;
}
Sort(f); List_2.Clear(); foreach (var item in f)
{
List_2.Add(item);
}
}
}