C++辅导:ArrayQueue,第1张

C++辅导:ArrayQueue,第2张

#include
  #define maxsize 10
  typedef struct
  {
  int elem[maxsize];
  int front,rear;
  }queue;
  void init_queue(queue *cp)
  {
  cp->front=0;
  cp->rear=0;
  }
  void en_queue(queue *cp,int x)
  {
  if((cp->rear+1)%maxsize==cp->front)
  printf("The quequ is full!!");
  else
  {
  cp->rear=(cp->rear+1)%maxsize;
  cp->elem[cp->rear]=x;
  }
  }
  int dl_queue(queue *cp)
  {
  if(cp->front==cp->rear)
  printf("The queue is empty!!");
  else
  {
  cp->front=(cp->front+1)%maxsize;
  return(cp->elem[cp->front]);
  }
  }
  void print(queue *cp)
  {
  int i;
  for(i=cp->front+1;irear;i++)
  {
  printf("[%d]",cp->elem[i]);
  }
  }
  void main()
  {
  int x,y;
  int select;
  queue *cp=NULL;
  init_queue(cp);
  do
  {
  printf("\n(1) Input a stack data");
  printf("\n(2) Output a stack data");
  printf("\n(3) Exit");
  printf("\nPlease select one:");
  scanf("%d",&select);
  switch(select)
  {
  case 1:printf("\nPlease input the data:");
  scanf("%d",&x);
  en_queue(cp,x);
  printf("\nThe queue is: ");
  print(cp);
  break;
  case 2:y=dl_queue(cp);
  printf("\nThe queue is: ");
  print(cp);
  printf("\nThe putout data is %d",y);
  break;
  case 3:break;
  }
  }
  while(select

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » C++辅导:ArrayQueue

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情