| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1078 人关注过本帖
标题:顺序循环队列
只看楼主 加入收藏
寻梦飞翔
Rank: 1
等 级:新手上路
帖 子:76
专家分:9
注 册:2010-3-15
结帖率:94.12%
收藏
已结贴  问题点数:5 回复次数:3 
顺序循环队列
输出不对,帮忙指点一下:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef struct cilqueue
{ int elem[MAXSIZE];
  int front,rear;
}cqueue,*queue;
queue setnull(queue Q)
{
  Q->front=MAXSIZE-1;
  Q->rear=MAXSIZE-1;
  return Q;
}
int qempty(queue Q)
{
  if(Q->rear==Q->front)
  return 1;
  else
  return 0;
}
void enqueue(queue Q,int e)
{
  if(Q->front==(Q->rear+1)%MAXSIZE)
  printf("队列已经满了.");
  else
  {
    Q->rear=(Q->rear+1)%MAXSIZE;
    Q->elem[Q->rear]=e;
  }
}
int ouqueue(queue Q,int *e)
{
  if(qempty(Q))
  printf("队列是空的.");
  else
  Q->front=(Q->front+1)%MAXSIZE;
  *e=Q->elem[Q->front];
  return *e;
}
main()
{ cqueue Q;
  int a;
  printf("请输入循环队列中的数据:");
  scanf("%d",&a);
  while(a!=0)
  {
    enqueue(&Q,a);
    scanf("%d",&a);
  }
  while(!qempty(&Q))
  {
    ouqueue(&Q,&a);
    printf("%d",a);
    printf("  ");
  }
   
}
搜索更多相关主题的帖子: 队列 顺序 
2010-04-07 21:44
寻梦飞翔
Rank: 1
等 级:新手上路
帖 子:76
专家分:9
注 册:2010-3-15
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2010-04-07 22:30
kingsroot
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:284
专家分:1159
注 册:2010-3-28
收藏
得分:5 
  Q.rear=0;
  Q.front=0;在main函数里面加上这2个  你没初始化变量
2010-04-07 22:41
寻梦飞翔
Rank: 1
等 级:新手上路
帖 子:76
专家分:9
注 册:2010-3-15
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef struct cilqueue
{ int elem[MAXSIZE];
  int front,rear;
}cqueue,*queue;
queue setnull(queue Q)
{
  Q->front=MAXSIZE-1;
  Q->rear=MAXSIZE-1;
  return Q;
}
int qempty(queue Q)
{
  if(Q->rear==Q->front)
  return 1;
  else
  return 0;
}
void enqueue(queue Q,int e)
{
  if(Q->front==(Q->rear+1)%MAXSIZE)
  printf("队列已经满了.");
  else
  {
    Q->rear=(Q->rear+1)%MAXSIZE;
    Q->elem[Q->rear]=e;
  }
}
int ouqueue(queue Q,int *e)
{
  if(qempty(Q))
  printf("队列是空的.");
  else
  Q->front=(Q->front+1)%MAXSIZE;
  *e=Q->elem[Q->front];
  return *e;
}
main()
{ cqueue Q;
  int a;
  setnull(&Q);
  printf("请输入循环队列中的数据:");
  scanf("%d",&a);
  while(a!=0)
  {
    enqueue(&Q,a);
    scanf("%d",&a);
  }
  while(!qempty(&Q))
  {
    ouqueue(&Q,&a);
    printf("%d",a);
    printf("  ");
  }
   
}
谢谢楼上的,我忘了初始化队列了……
2010-04-08 12:17
快速回复:顺序循环队列
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020126 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved