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

#define MAXSIZE 100

typedef int elemType;
typedef struct Queue
{
  elemType *base;//动态分配空间基址
  int front;        //标示队首
  int rear;        //标示队尾
}Queue,*ptr_Queue;

ptr_Queue Init_Queue(void)
{//初始化一个队列
  ptr_Queue queue;
  queue=new Queue;
  queue->base=(elemType *)malloc(MAXSIZE * sizeof(elemType));
  if(!queue->base)
  {
    printf("allocation is failed.\n");
    return NULL;
  }
  else
  {
    queue->front=queue->rear=0;
    return queue;
  }
}

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

int QueueLength(ptr_Queue queue)
{//获取队列的长度
  return ((queue->rear-queue->front+MAXSIZE)%MAXSIZE);
}

bool IsQueueFull(ptr_Queue queue)
{//判断队列是否满了
  if((queue->rear+1)%MAXSIZE==queue->front)
  {
    return true;
  }
  return false;
}

void Enter_Queue(ptr_Queue queue,elemType elem)
{//入队
  if(IsQueueFull(queue))
  {//队列已满,不能再入队
    printf("The queue is full,there is no room for you to enter a element.\n");
  }
  else
  {
    queue->base[queue->rear]=elem;
    queue->rear=(queue->rear+1)%MAXSIZE;
  }
}

bool Delete_Queue(ptr_Queue queue,elemType *elem)
{
  if(IsQueueEmpty(queue))
  {//空队列
    printf("The queue is empty,you can't delete element from it.\n");
    return false;
  }
  else
  {
    *elem=queue->base[queue->front];
    queue->front=(queue->front+1)%MAXSIZE;
    return true;
  }
}

bool Position_Elem(ptr_Queue queue,int pos,elemType *elem)
{
  if(pos<1 || pos>QueueLength(queue))
  {
    printf("The position is invalidate.\n");
    return false;
  }
  else
  {
    if(IsQueueEmpty(queue))
    {
      printf("The queue is empty.\n");
      return false;
    }
    else
    {
      *elem=queue->base[pos-1];
      return true;
    }
  }
}

bool Front_Element(ptr_Queue queue,elemType *elem)
{
  if(IsQueueEmpty(queue))
  {
    printf("The queue is empty.\n");
    return false;
  }
  else
  {
    *elem=queue->base[queue->front];
    return true;
  }
}

bool Rear_Element(ptr_Queue queue,elemType *elem)
{
  if(IsQueueEmpty(queue))
  {
    printf("The queue is empty.\n");
    return false;
  }
  else
  {
    *elem=queue->base[queue->rear-1];
    return true;
  }
}

void ClearQueue(ptr_Queue queue)
{
  elemType elem;
  while(queue->front!=queue->rear)
  {
    Delete_Queue(queue,&elem);
  }
}
void VisitQueue(ptr_Queue queue)
{
  int i;
  for(i=queue->front;i!=queue->rear;++i)
  {
    printf("%4d",queue->base[i]);
  }
  printf("\n");
}
    测试代码:
   
#include "stdafx.h"
#include "sequence_queue.h"
#include <conio.h>

int _tmain(int argc, _TCHAR* argv[])
{
  int i;
  int pos;
  elemType elem;
  ptr_Queue queue;
  queue=Init_Queue();
  if(queue)
  {
    printf("We have a new queue.\n");
  }
  printf("The length of the new queue is:%d\n",QueueLength(queue));
  Enter_Queue(queue,5);
  Enter_Queue(queue,8);
  Enter_Queue(queue,11);
  Enter_Queue(queue,25);
  VisitQueue(queue);
  printf("The length of the queue is:%d\n",QueueLength(queue));
  Delete_Queue(queue,&elem);
  VisitQueue(queue);
  printf("The length of the queue is:%d\n",QueueLength(queue));
  Delete_Queue(queue,&elem);
  Delete_Queue(queue,&elem);
  VisitQueue(queue);
  printf("The length of the queue is:%d\n",QueueLength(queue));
  Delete_Queue(queue,&elem);
  Delete_Queue(queue,&elem);
  for(i=0;i<6;++i)
  {
    Enter_Queue(queue,i*3+5);
  }
  VisitQueue(queue);
  printf("The length of the queue is:%d\n",QueueLength(queue));
  printf("Please input the position:");
  scanf("%d",&pos);
  if(Position_Elem(queue,pos,&elem))
  {
    printf("The elem at the position %d is %d\n",pos,elem);
  }
  if(Front_Element(queue,&elem))
  {
    printf("The front_elem is %d\n",elem);
  }
  if(Rear_Element(queue,&elem))
  {
    printf("The rear_elem is %d\n",elem);
  }
  ClearQueue(queue);
  Delete_Queue(queue,&elem);
  getch();
  return 0;
}