头文件:
   
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

typedef int elemType;
typedef struct Queue_Node
{//结点结构
  elemType value;
  struct Queue_Node *next;
}Queue_Node,*ptr_Queue_Node;

typedef struct Queue_List
{//链表结构
  ptr_Queue_Node front;
  ptr_Queue_Node rear;
}Queue_List,*ptr_Queue_List;

ptr_Queue_List Init_QueueList(void)
{//初始化一个空的链队列(带头结点)
  ptr_Queue_List queuelist;
  queuelist=new Queue_List;
  queuelist->front=new Queue_Node;
  queuelist->rear=queuelist->front;
  queuelist->rear->next=NULL;
  return queuelist;
}

bool Is_QueueList_Empty(ptr_Queue_List queuelist)
{//判断队列是否为空
  if(queuelist->front==queuelist->rear)
  {
    return true;
  }
  return false;
}

int QueueList_Length(ptr_Queue_List queuelist)
{//获取队列的长度
  ptr_Queue_Node p;
  int len=0;
  p=queuelist->front;
  while(p!=queuelist->rear)
  {
    p=p->next;
    ++len;
  }
  return len;
}

void Enter_QueueList(ptr_Queue_List queuelist,elemType elem)
{//入队
  ptr_Queue_Node p;
  p=new Queue_Node;
  p->value=elem;
  if(Is_QueueList_Empty(queuelist))
  {
    queuelist->front->next=p;
    queuelist->rear=p;
    p->next=NULL;
  }
  else
  {
    queuelist->rear->next=p;
    queuelist->rear=p;
    p->next=NULL;
  }
}

void Delete_QueueList(ptr_Queue_List queuelist,elemType *elem)
{//出队
  ptr_Queue_Node p;
  if(Is_QueueList_Empty(queuelist))
  {
    printf("The queuelist is empty,you can't delete head_element from it.\n");
  }
  else
  {
    if(QueueList_Length(queuelist)==1)
    {//链队列长度为1
      p=queuelist->front->next;
      *elem=p->value;
      free(p);
      queuelist->rear=queuelist->front;
      queuelist->rear->next=NULL;
    }
    else
    {
      p=queuelist->front->next;
      *elem=p->value;
      queuelist->front->next=p->next;
      free(p);
    }
  }
}

bool Pre_Element(ptr_Queue_List queuelist,int pos,elemType *elem)
{
  ptr_Queue_Node p=queuelist->front->next;
  int i;
  if(pos<1 || pos>QueueList_Length(queuelist))
  {
    printf("The queuelist is empty.\n");
    return false;
  }
  else
  {
    if(Is_QueueList_Empty(queuelist))
    {
      printf("The queuelist is empty.\n");
      return false;
    }
    else
    {
      if(pos==1)
      {//队首结点没有前驱结点
        printf("The head_node doesn't have a pre_node.\n");
        return false;
      }
      else
      {
        for(i=1;i<pos-1;++i)
        {
          p=p->next;
        }
        *elem=p->value;
        return true;
      }
    }
  }
}

bool Next_Element(ptr_Queue_List queuelist,int pos,elemType *elem)
{
  ptr_Queue_Node p=queuelist->front->next;
  int i;
  if(pos<1 || pos>QueueList_Length(queuelist))
  {
    printf("The queuelist is empty.\n");
    return false;
  }
  else
  {
    if(Is_QueueList_Empty(queuelist))
    {
      printf("The queuelist is empty.\n");
      return false;
    }
    else
    {
      if(pos==QueueList_Length(queuelist))
      {//队尾结点没有后继结点
        printf("The rear_node doesn't have a next_node.\n");
        return false;
      }
      else
      {
        for(i=1;i<pos;++i)
        {//找到pos位置处的结点
          p=p->next;
        }
        *elem=p->next->value;
        return true;
      }
    }
  }
}

bool Cur_Element(ptr_Queue_List queuelist,int pos,elemType *elem)
{
  ptr_Queue_Node p=queuelist->front->next;
  int i;
  if(pos<1 || pos>QueueList_Length(queuelist))
  {
    printf("The position is invalidate.\n");
    return false;
  }
  else
  {
    if(Is_QueueList_Empty(queuelist))
    {
      printf("The queuelist is empty.\n");
      return false;
    }
    else
    {
      for(i=1;i<pos;++i)
      {//找到pos位置处的结点
        p=p->next;
      }
      *elem=p->value;
      return true;
    }
  }
}

bool Head_Element(ptr_Queue_List queuelist,elemType *elem)
{//得到队首元素
  if(Is_QueueList_Empty(queuelist))
  {
    printf("The queuelist is empty.\n");
    return false;
  }
  else
  {
    *elem=queuelist->front->next->value;
    return true;
  }
}

bool Rear_Element(ptr_Queue_List queuelist,elemType *elem)
{//得到队尾元素
  if(Is_QueueList_Empty(queuelist))
  {
    printf("The queuelist is empty.\n");
    return false;
  }
  else
  {
    *elem=queuelist->rear->value;
    return true;
  }
}

void Destroy_QueueList(ptr_Queue_List queuelist)
{
  ptr_Queue_Node p=queuelist->front->next;
  ptr_Queue_Node q;
  while(p!=queuelist->rear)
  {//释放链队列中的结点
    q=p->next;
    free(p);
    p=q;
  }
  free(queuelist->rear);//释放队尾结点
  free(queuelist->front);//释放队首结点
}

void Visit_QueueList(ptr_Queue_List queuelist)
{
  ptr_Queue_Node p=queuelist->front->next;
  while(p)
  {
    printf("%4d",*p);
    p=p->next;
  }
  printf("\n");
}
   测试代码:
   
#include "stdafx.h"
#include "list_queue.h"
#include <conio.h>


int _tmain(int argc, _TCHAR* argv[])
{
  elemType elem;
  ptr_Queue_List queuelist;
  queuelist=Init_QueueList();
  if(queuelist)
  {
    printf("We have a new queuelist.\n");
    printf("The length of the new queuelist is:%d\n",QueueList_Length(queuelist));
  }
  Enter_QueueList(queuelist,3);
  Enter_QueueList(queuelist,8);
  Enter_QueueList(queuelist,11);
  Enter_QueueList(queuelist,25);
  Enter_QueueList(queuelist,33);
  Visit_QueueList(queuelist);
  printf("The length of the queuelist is:%d\n",QueueList_Length(queuelist));
  if(Head_Element(queuelist,&elem))
  {
    printf("The head_elem is %d\n",elem);
  }
  if(Rear_Element(queuelist,&elem))
  {
    printf("The rear_elem is %d\n",elem);
  }
  if(Pre_Element(queuelist,1,&elem))
  {
    printf("The pre_element of position 1 is %d\n",elem);
  }
  if(Pre_Element(queuelist,3,&elem))
  {
    printf("The pre_element of position 3 is %d\n",elem);
  }
  if(Next_Element(queuelist,QueueList_Length(queuelist),&elem))
  {
    printf("The next_elem of position %d is %d\n",QueueList_Length(queuelist),elem);
  }
  if(Next_Element(queuelist,3,&elem))
  {
    printf("The next_elem of position 3 is %d\n",elem);
  }
  if(Cur_Element(queuelist,2,&elem))
  {
    printf("The cur_elem of position 2 is %d\n",elem);
  }
  if(Cur_Element(queuelist,9,&elem))
  {
    printf("The cur_elem of position 9 is %d\n",elem);
  }
  Delete_QueueList(queuelist,&elem);
  Visit_QueueList(queuelist);
  if(Head_Element(queuelist,&elem))
  {
    printf("The head_elem is %d\n",elem);
  }
  Delete_QueueList(queuelist,&elem);
  Visit_QueueList(queuelist);
  if(Rear_Element(queuelist,&elem))
  {
    printf("The rear_elem is %d\n",elem);
  }
  printf("The length of the queuelist is %d\n",QueueList_Length(queuelist));
  Delete_QueueList(queuelist,&elem);
  Visit_QueueList(queuelist);
  Delete_QueueList(queuelist,&elem);
  Delete_QueueList(queuelist,&elem);
  printf("The length of the queuelist is %d\n",QueueList_Length(queuelist));
  Delete_QueueList(queuelist,&elem);
  getch();
  return 0;
}