public class Node {
private int element;
private Node next;
private Node prev;
public int getElement()
{return element;}
public void setElement(int e)
{ element = e;}
public Node getNext()
{return next;}
public void setNext(Node n)
{ next = n;}
public Node getPrev()
{returnprev;}
publicvoid setPrev(Node n)
{prev= n;}
}
public class Node {
private int element;
private Node next;
private Node prev;
public int getElement()
{return element;}
public void setElement(int e)
{ element = e;}
public Node getNext()
{return next;}
public void setNext(Node n)
{ next = n;}
public Node getPrev()
{returnprev;}
publicvoid setPrev(Node n)
{prev= n;}
}
struct Element
{
Element * m_prev;
Element * m_next;
...
...
};
class List
{
Element * m_first;
Element * m_last;
void swap(Element * e1, Element * e2);
};
namespace List
{
class Element
{
public Element(int value)
{
this.Value = value;
this.Previous = null;
this.Next = null;
}
public Element(int value, Element node)
{
this.Value = value;
node.Next = this;
this.Previous = node;
}
public Element Previous { get; set; }
public Element Next { get; set; }
public int Value { get; set; }
}
class LList
{
public Element foot;
public void Add(int value)
{
this.foot = this.foot == null ? new Element(value) : new Element(value, this.foot);
}
public void swap(Element node1, Element node2)
{
Element tmp = new Element(0);
tmp.Next = node2.Next;
tmp.Previous = node2.Previous;
node2.Next = node1.Next;
node2.Previous = node1.Previous;
if (node1.Next != null)
{
node1.Next.Previous = node2;
}
if (node1.Previous != null)
{
node1.Previous.Next = node2;
}
node1.Next = tmp.Next;
node1.Previous = tmp.Previous;
if (tmp.Next != null)
{
tmp.Next.Previous = node1;
}
if (tmp.Previous != null)
{
tmp.Previous.Next = node1;
}
if (node1.Next == null)
{
foot = node1;
}
}
}
}
namespace List
{
class Element
{
public Element(int value)
{
this.Value = value;
this.Previous = null;
this.Next = null;
}
public Element(int value, Element node)
{
this.Value = value;
node.Next = this;
this.Previous = node;
}
public Element Previous { get; set; }
public Element Next { get; set; }
public int Value { get; set; }
}
class LList
{
public Element foot;
public void Add(int value)
{
this.foot = this.foot == null ? new Element(value) : new Element(value, this.foot);
}
public void swap(Element node1, Element node2)
{
Element tmp = new Element(0);
tmp.Next = node2.Next;
tmp.Previous = node2.Previous;
node2.Next = node1.Next;
node2.Previous = node1.Previous;
if (node1.Next != null)
{
node1.Next.Previous = node2;
}
if (node1.Previous != null)
{
node1.Previous.Next = node2;
}
node1.Next = tmp.Next;
node1.Previous = tmp.Previous;
if (tmp.Next != null)
{
tmp.Next.Previous = node1;
}
if (tmp.Previous != null)
{
tmp.Previous.Next = node1;
}
if (node1.Next == null)
{
foot = node1;
}
}
}
}
class Element
{
public Element(int value)
{
this.Value = value;
this.Previous = null;
this.Next = null;
}
public Element(int value, Element node)
{
this.Value = value;
node.Next = this;
this.Previous = node;
}
public Element Previous { get; set; }
public Element Next { get; set; }
public int Value { get; set; }
}
class LList
{
public Element foot;
public void Add(int value)
{
this.foot = this.foot == null ? new Element(value) : new Element(value, this.foot);
}
....
public Element(int value, Element node)
{
this.Value = value;
node.Next = this;
this.Previous = node;
}