for k-1 if first ShowFirst second ShowBack first Empty second AddLast

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
for(i=0;i<k-1;i++)
{
if(first.ShowFirst()<=second.ShowBack()&& first.Empty())
{
second.AddLast(first.ShowFirst());
}//ставит назад
if(first.ShowFirst()>=second.ShowBack()&& first.Empty())
{
second.AddFirst(first.ShowFirst());
}//ставить вперед
if(first.ShowFirst()<=second.ShowFirst() && first.ShowFirst()>=second.ShowBack() && first.Empty())
{
n=0;
while(first.ShowFirst()<=second.ShowFirst() && first.ShowFirst()>=second.ShowBack() && first.Empty())
{
second.AddLast(second.ShowFirst());
second.DeleteFirst();
n++;
}
second.AddFirst(first.ShowFirst());
for(;n>0;n--)
{
second.AddFirst(second.ShowBack());
second.DeleteLast();
}
}first.DeleteFirst();
}