头文件:
   
#include <iostream>
using namespace std;

typedef struct Node
{//结点结构
  int value;
  struct Node *pre,*next;
}Node,*Link;

typedef struct List
{//链表结构
  Link head,tail;
  int length;
}List,*LinkList;

LinkList NewList(void)
{
  LinkList list;
  list=new List;//为链表指针分配空间
  list->head=new Node;//为表头结点分配空间
  list->tail=list->head;
  list->tail->next=NULL;
  list->length=0;
  return list;
}

int ListLength(List list)
{
  return list.length;
}

bool IsListEmpty(List list)
{
  if(list.length==0)
    return true;
  return false;
}

void ClearList(LinkList list)
{//清空链表,并释放每个结点的空间
  Link p=list->head->next;
  Link q;
        while(p!=list->tail)
  {
    q=p->next;
    free(p);
    p=q;
  }
  free(p);//释放尾结点
  list->tail=list->head;
  list->length=0;
}

void DestroyList(LinkList list)
{
  ClearList(list);
  free(list->head);
  free(list->tail);
}

void InsertElemToList(LinkList list,int pos,int elem)
{
  Link p;
  p=new Node;
  p->value=elem;
  if(pos<1 || pos>ListLength(*list)+1)
  {
    cout<<"The position is invalidate."<<endl;
  }
  else
  {
    if(pos==1)
    {//插在表头
      if(IsListEmpty(*list))
      {//空表
        list->head->next=p;
        list->tail=p;
        p->pre=list->head;
        p->next=NULL;
      }
      else
      {//非空表
        p->next=list->head->next;
        list->head->next->pre=p;
        list->head->next=p;
      }
    }
    else if(pos==ListLength(*list)+1)
    {//插在表尾
      list->tail->next=p;
      p->pre=list->tail;
      list->tail=p;
      p->next=NULL;
    }
    else
    {
      Link q=list->head->next;
      for(int i=1;i<pos-1;++i)
      {
        q=q->next;
      }
      p->next=q->next;
      p->pre=q;
      q->next->pre=p;
      q->next=p;
    }
    ++list->length;
  }
}

void DeleteElemFromList(LinkList list,int pos,int &elem)
{
  if(pos<1 || pos>ListLength(*list))
  {
    cout<<"The position is invalidate."<<endl;
  }
  else
  {
    if(IsListEmpty(*list))
    {//表空
      cout<<"The list is empty,you can't delete element."<<endl;
    }
    else
    {//表非空
      if(pos==1)
      {//删除表头
        if(ListLength(*list)==1)
        {//表长为1
          list->tail=list->head;
          list->head->next=NULL;
        }
        else
        {
          Link q=list->head->next;
          list->head->next=q->next;
          q->next->pre=NULL;
          elem=q->value;
          free(q);
        }
      }
      else if(pos==ListLength(*list))
      {
        Link q=list->tail;
        list->tail=list->tail->pre;
        list->tail->next=NULL;
        elem=q->value;
        free(q);
      }
      else
      {
        Link q=list->head->next;
        for(int i=1;i<pos;++i)
        {//找到pos位置的结点
          q=q->next;
        }
        q->pre->next=q->next;
        q->next->pre=q->pre;
        elem=q->value;
        free(q);
      }
      --list->length;
    }
  }
}

bool PreElem(List list,int pos,int &elem)
{//判断 pos位置的结点有无前驱,若有则用elem接收其后继的值
  if(IsListEmpty(list))
  {
    cout<<"Sorry,the list is empty.";
  }
  else
  {
    if(pos<1 || pos>ListLength(list))
    {
      cout<<"The position is invalidate."<<endl;
      return false;
    }
    else    
    {    
      if(pos==1)
      {//表头
        cout<<"This position doesn't have a pre_element."<<endl;
        return false;
      }
      else
      {
        Link p=list.head->next;
        for(int i=1;i<pos;++i)
        {//找到pos位置的结点
          p=p->next;
        }
        elem=p->pre->value;
        return true;
      }
    }
  }
}

bool NextElem(List list,int pos,int &elem)
{//判断 pos位置的结点有无后继,若有则用elem接收其后继的值
  if(IsListEmpty(list))
  {
    cout<<"Sorry,the list is empty.";
  }
  else
  {
    if(pos<1 || pos>ListLength(list))
    {
      cout<<"The position is invalidate."<<endl;
      return false;
    }
    else    
    {
      if(pos==ListLength(list))
      {//表尾
        cout<<"This position doesn't have a next_element."<<endl;
        return false;
      }
      else
      {
        Link p=list.head->next;
        for(int i=1;i<pos;++i)
        {
          p=p->next;
        }
        elem=p->next->value;
        return true;
      }
    }
  }    
}

bool CurrentElem(List list,int pos,int &elem)
{//获得pos位置处得元素,并用elem接收
  if(IsListEmpty(list))
  {
    cout<<"Sorry,the list is empty.";
    return false;
  }
  else
  {
    if(pos<1 || pos>ListLength(list))
    {
      cout<<"The position is invalidate."<<endl;
      return false;
    }
    else
    {

      Link p=list.head->next;
      for(int i=1;i<pos;++i)
      {
        p=p->next;
      }
      elem=p->value;
      return true;
    }
  }
}

bool GetHead(List list,int &elem)
{//如果链表不空,则返回表头元素,用elem接收
  if(IsListEmpty(list))
  {
    cout<<"The list is empty."<<endl;
    return false;
  }
  else
  {
    elem=list.head->next->value;
    return true;
  }
}

bool GetTail(List list,int &elem)
{//如果链表不空,则返回表尾元素,用elem接收
  if(IsListEmpty(list))
  {
    cout<<"The list is empty."<<endl;
    return false;
  }
  else
  {
    elem=list.tail->value;
    return true;
  }
}

void VisitElemFromList(List list)
{
  Link p=list.head->next;
  while(p)
  {
    cout<<p->value<<' ';
    p=p->next;
  }
  cout<<endl;
}
    测试代码:
   
#include "stdafx.h"
#include <conio.h>
#include "double_direction_list.h"


int _tmain(int argc, _TCHAR* argv[])
{
  int e;
  LinkList list;
  list=NewList();
  if(IsListEmpty(*list))
    cout<<"The list is empty."<<endl;
  cout<<"The length of the list is:"<<ListLength(*list)<<endl;
  InsertElemToList(list,1,3);
  InsertElemToList(list,2,5);
  VisitElemFromList(*list);
  ClearList(list);
  InsertElemToList(list,1,8);
  InsertElemToList(list,3,9);
  InsertElemToList(list,ListLength(*list),10);
  InsertElemToList(list,ListLength(*list)+1,33);
  VisitElemFromList(*list);
  cout<<"The length of the list is:"<<ListLength(*list)<<endl;
  if(GetHead(*list,e))
  {
    cout<<"The head_elem of the list is:"<<e<<endl;
  }
  if(GetTail(*list,e))
  {
    cout<<"The tail_elem of the list is:"<<e<<endl;
  }
  InsertElemToList(list,2,22);
  InsertElemToList(list,4,55);
  InsertElemToList(list,ListLength(*list),99);
  VisitElemFromList(*list);
  int elem;
  DeleteElemFromList(list,1,elem);
  VisitElemFromList(*list);
  cout<<"The length of the list is:"<<ListLength(*list)<<endl;
  if(GetHead(*list,e))
  {
    cout<<"The head_elem of the list is:"<<e<<endl;
  }
  if(GetTail(*list,e))
  {
    cout<<"The tail_elem of the list is:"<<e<<endl;
  }
  DeleteElemFromList(list,3,elem);
  VisitElemFromList(*list);
  cout<<"The length of the list is:"<<ListLength(*list)<<endl;
  DeleteElemFromList(list,ListLength(*list),elem);
  VisitElemFromList(*list);
  cout<<"The length of the list is:"<<ListLength(*list)<<endl;
  if(GetHead(*list,e))
  {
    cout<<"The head_elem of the list is:"<<e<<endl;
  }
  if(GetTail(*list,e))
  {
    cout<<"The tail_elem of the list is:"<<e<<endl;
  }
  int temp;
  if(PreElem(*list,2,temp))
    cout<<"The pre_element of this position is:"<<temp<<endl;
  if(PreElem(*list,1,temp))
    cout<<"The pre_element of this position is:"<<temp<<endl;
  if(NextElem(*list,2,temp))
    cout<<"The nex_element of this position is:"<<temp<<endl;
  if(NextElem(*list,ListLength(*list),temp))
    cout<<"The next_element of this position is:"<<temp<<endl;
  if(CurrentElem(*list,2,temp))
    cout<<"The current_element of this position is:"<<temp<<endl;
  if(CurrentElem(*list,ListLength(*list)+2,temp))
    cout<<"The current_element of this position is:"<<temp<<endl;
  ClearList(list);
  if(CurrentElem(*list,2,temp))
    cout<<"The current_element of this position is:"<<temp<<endl;
  getch();
  return 0;
}