| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 429 人关注过本帖
标题:帮忙程序找下错误
只看楼主 加入收藏
yaohuitc
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-8-19
收藏
 问题点数:0 回复次数:0 
帮忙程序找下错误
//说明:这是一个队列的应用,出了些我搞不清楚的问题,请高手帮忙看看,最好是帮忙运行运行

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

struct QueueRecord;
typedef struct QueueRecord * Queue;

int IsEmpty( Queue Q );
int IsFull( Queue Q );
static int Succ( int Value, Queue Q );
void Enqueue( char x, Queue Q );
void Dequeue( Queue Q );
Queue InitQueue();
void print ( Queue Q );

#define MAX_SIZE 20;

struct QueueRecord
{
    int Capacity;
    int Front;
    int Rear;
    int Size;
    char *Array;
};
int IsEmpty( Queue Q )
{
    return Q->Size == 0;
}
int IsFull( Queue Q )
{
    return Q->Size == Q->Capacity;
}
static int Succ( int Value, Queue Q )
{
    if ( ++Value == Q->Capacity )
        Value = 0;
    return Value;
}
void Enqueue( char x, Queue Q )
{
    if ( IsFull( Q ) )
        printf("Full queue!");
    else
    {
        Q->Size++;
        Q->Rear = Succ( Q->Rear, Q );
        Q->Array[ Q->Rear ] = x;
    }
}
void Dequeue( Queue Q )
{
    if ( IsEmpty( Q ) )
    {
        printf("Empty Queue!");
        exit(-1);
    }
    Q->Size--;
    Q->Front = Succ( Q->Front, Q );
}
Queue InitQueue( void )                      //这里我是想创建一个队列的,但是感觉有问题,又不知道出什么错
{
    Queue Q;
    Q->Array = (char * ) calloc (20, sizeof( char ));
    if ( Q->Array == NULL )
        exit(-1);
    Q->Capacity = MAX_SIZE;
    Q->Front = 1;
    Q->Rear = 0;
    Q->Size = 0;
    return Q;
}
void print ( Queue Q )
{
    int i, j;
    i = Q->Front;
    for ( j = 0; j <= Q->Size; j++)
    {
        printf("%c ", Q->Array[i]);
        if( ++i > Q->Capacity )
            i = 0;
    }
}
main()
{
    int random_i, i;
    char x;
    Queue Q;
    Q = InitQueue();
    randomize();
    random_i = random( 20 );
    for ( i = 0; i < random_i; i++)         //运行的时候循环好像有问题,现在自己都迷糊了
    {
        printf("Input Element:");
        scanf("%c", &x);
        Enqueue( x, Q );
    }
    print( Q );
    randomize();
    random_i = random( 20 );
    for ( i = 0; i < random_i; i++ )
        Dequeue( Q );
    print( Q );
}
搜索更多相关主题的帖子: include 最好 
2008-10-05 00:25
快速回复:帮忙程序找下错误
数据加载中...
 
   



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

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