using System;
namespace ConsoleApplication1
{
class node
{
public int value;
public node next;
public node previous;
public node maxNode(node x,node y)
{
if(y.value>=x.value)
return y;
else
return x;
}
}
class Class1
{
/// <summary>
///
/// </summary>
[STAThread]
static void Main(string[] args)
{
//create a double linked list
//each input of data should be ended with enter
//if the input in finished,please press space,than enter
string buffer;
int nodeAccount=0;
node superHead,superTail;
node head=new node();
superHead=head;
superHead.previous=null;
while((buffer=Console.ReadLine())!=" ")
{
head.value=Int32.Parse(buffer);
node tail=new node();
head.next=tail;
tail.previous=head;
head=tail;
nodeAccount++;
}
superTail=head;
superTail.next=null;
//sort
int outer,inner;
node temp;
node maxIndex;
for(outer=nodeAccount;outer>0;outer--)
{
head=superHead;
maxIndex=superHead;
for(inner=0;inner<outer;inner++)
{
maxIndex=head.maxNode(maxIndex,head);
head=head.next;
}
if(head!=null&&maxIndex.previous!=null)
{
head=head.previous;
//8 pointer exchanged
temp=maxIndex.next;
maxIndex.next=head.next;
head.next=temp;
temp=maxIndex.previous;
maxIndex.previous=head.previous;
head.previous=temp;
temp=maxIndex.next.previous;
maxIndex.next.previous=head.next.previous;
head.next.previous=temp;
temp=maxIndex.previous.next;
maxIndex.previous.next=head.previous.next;
head.previous.next=temp;
}
}
head=superHead;
while(head!=superTail)//head is used as temporary variable
{
Console.WriteLine(head.value);
head=head.next;
}
}
}
}
/*
用单链表,只交换节点中的数据更方便的
*/
namespace ConsoleApplication1
{
class node
{
public int value;
public node next;
public node previous;
public node maxNode(node x,node y)
{
if(y.value>=x.value)
return y;
else
return x;
}
}
class Class1
{
/// <summary>
///
/// </summary>
[STAThread]
static void Main(string[] args)
{
//create a double linked list
//each input of data should be ended with enter
//if the input in finished,please press space,than enter
string buffer;
int nodeAccount=0;
node superHead,superTail;
node head=new node();
superHead=head;
superHead.previous=null;
while((buffer=Console.ReadLine())!=" ")
{
head.value=Int32.Parse(buffer);
node tail=new node();
head.next=tail;
tail.previous=head;
head=tail;
nodeAccount++;
}
superTail=head;
superTail.next=null;
//sort
int outer,inner;
node temp;
node maxIndex;
for(outer=nodeAccount;outer>0;outer--)
{
head=superHead;
maxIndex=superHead;
for(inner=0;inner<outer;inner++)
{
maxIndex=head.maxNode(maxIndex,head);
head=head.next;
}
if(head!=null&&maxIndex.previous!=null)
{
head=head.previous;
//8 pointer exchanged
temp=maxIndex.next;
maxIndex.next=head.next;
head.next=temp;
temp=maxIndex.previous;
maxIndex.previous=head.previous;
head.previous=temp;
temp=maxIndex.next.previous;
maxIndex.next.previous=head.next.previous;
head.next.previous=temp;
temp=maxIndex.previous.next;
maxIndex.previous.next=head.previous.next;
head.previous.next=temp;
}
}
head=superHead;
while(head!=superTail)//head is used as temporary variable
{
Console.WriteLine(head.value);
head=head.next;
}
}
}
}
/*
用单链表,只交换节点中的数据更方便的
*/