| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1029 人关注过本帖
标题:舞伴问题 帮我看看 错在哪里
只看楼主 加入收藏
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:6 
舞伴问题 帮我看看 错在哪里
#include<iostream>
#include<stdio.h>



#define MAX_DANCERS 100
#define queuesize 100

typedef struct{
    char name[20];
    char sex;
}person;

typedef person DataType;


typedef struct{

    DataType data[queuesize];
    int front;
    int rear;
    int count;
}cirqueue;


void initial(cirqueue *Q)
{Q->rear =0;
Q->front =0;
Q->count =0;



}


int isempty(cirqueue *Q)
{return Q->count ==0;




}

int isfull(cirqueue *Q)
{return queuesize==Q->count;



}



void enqueue(cirqueue *Q,DataType x)
{if(isfull(Q))
    {printf ("duiman");
     exit(1);


    }
Q->count ++;
Q->data [Q->rear ]=x;
Q->rear =(Q->rear +1)%queuesize;





}
  
void dequeue(cirqueue *Q)
{DataType temp;
    if(isempty(Q))
    {printf("duikong");
    exit(1);



    }

Q->count --;
temp=Q->data [Q->front ];
Q->front =(Q->front +1)%queuesize;




}


DataType Front(cirqueue *Q)
{if(isempty(Q))
{printf("duikog");
exit(1);



}

return Q->data [Q->front ];


}










void dancerparter(person dancer[],int num)
{int i;
person p;

cirqueue mdancer,fdancer;
initial(&mdancer);
initial(&fdancer);

for(i=0;i<num;i++)
    {p=dancer[i];
    if(p.sex =='f')
        enqueue(&fdancer,p);
    else
        enqueue(&mdancer,p);





    }

printf("舞队是:\n \n");

while(!isempty(&mdancer)&&!isempty(&fdancer))
    {
   
    p=dequeue(&mdancer);
     printf("%s ",p.name );
     p=dequeue(&fdancer);
     printf("%s ",p.name );


    }


if(isempty(&mdancer))
    {printf("还有%d个男士等待下一轮\n",fdancer.count );
     p=Front(&fdancer);
     printf("%s ",p.name );

    }
else if(isempty(&fdancer))
    {printf("还有%d个女士等待下一轮\n",mdancer.count );
     p=Front(&mdancer);
     printf("%s ",p.name );

    }



}



void initialdancer(person dancer[])
{}

void main()
{person dancer[MAX_DANCERS];
int n=93;
initialdancer(dancer);
dancerparter(dancer,93);



}



  error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
 error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
执行 cl.exe 时出错.




提示这样的错误


我觉的也没错啊
挺符合逻辑的



谁要是解决这个问题 你要什么我给什么(论坛上的)












[ 本帖最后由 小兔子慢慢 于 2010-3-1 11:56 编辑 ]
搜索更多相关主题的帖子: 舞伴 
2010-03-01 08:09
JZ_ZCCZ
Rank: 2
等 级:论坛游民
帖 子:17
专家分:17
注 册:2010-2-25
收藏
得分:1 
想想!
2010-03-01 10:36
小J
Rank: 8Rank: 8
等 级:等待验证会员
威 望:1
帖 子:282
专家分:704
注 册:2009-6-18
收藏
得分:2 
p=dequeue(&mdancer);
p=dequeue(&fdancer);
你的dequeue()函数返值的类型却是void
没有帮你改你自己好好想想怎么改吧

[ 本帖最后由 小J 于 2010-3-1 12:41 编辑 ]
2010-03-01 12:38
小J
Rank: 8Rank: 8
等 级:等待验证会员
威 望:1
帖 子:282
专家分:704
注 册:2009-6-18
收藏
得分:4 
给一个我写的吧
我是用栈做的c环境vc6.0下通过

[ 本帖最后由 小J 于 2010-3-1 12:42 编辑 ]
2010-03-01 12:39
小J
Rank: 8Rank: 8
等 级:等待验证会员
威 望:1
帖 子:282
专家分:704
注 册:2009-6-18
收藏
得分:3 
#include "stdio.h"
#include "string.h"
typedef struct
{
    char name[10];
    char sex[3];
}Human;
typedef struct
{
    Human elem[10];
    int front;
    int next;
}Queue;
Queue init()
{
    Queue q;
    q.front=q.next=-1;
    return q;
}
void enter_queue(Queue *q,Human s)
{
    q->next++;
    strcpy(q->elem[q->next].name,s.name);
    strcpy(q->elem[q->next].sex,s.sex);
}
void print_queue(Queue q)
{
    int i;
    for(i=0;i<=q.next;i++)
    {
        printf("%-10s",q.elem[i].name);
    }
}
int IsNull(Queue q)
{
    if(q.front==q.next)
        return 0;
    else
        return 1;
}
void output_queue(Queue *q,Human *s)
{
    q->front++;
    strcpy((*s).name,q->elem[q->front].name);
}
void match(Queue *man,Queue *woman)
{
    Human h;
    printf("系统自动分配的舞伴是:\n");
    printf("男士**************女士\n");
    while(IsNull(*man) && IsNull(*woman))
    {
        output_queue(man,&h);
        printf("%3s",h.name);
        output_queue(woman,&h);
        printf("%20s",h.name);
        printf("\n");

    }
}
void left(Queue q)
{
    printf("还没有舞伴的是:\n");
    printf("姓名***************性别\n");
    while(IsNull(q))
    {
        q.front++;
        printf("%-20s%s\n",q.elem[q.front].name,q.elem[q.front].sex);
    }
}
main()
{
    int i;
    Queue man,woman;
    Human s[10]={"李雷","男","韩梅梅","女","Jim","男","Lily","女","Lucy","女","林涛","男","王艳","女","萧红","女","张燕","女","李攀","男"};
    man=init();
    woman=init();
    printf("参加舞会的人有:\n");
    printf("姓名*************性别\n");
    for(i=0;i<10;i++)
    {
        printf("%-18s%s\n",s[i].name,s[i].sex);
    }
    for(i=0;i<10;i++)
    {
        if(strcmp(s[i].sex,"男")==0)
        {
            enter_queue(&man,s[i]);
        }
        if(strcmp(s[i].sex,"女")==0)
        {
            enter_queue(&woman,s[i]);
        }
    }
    printf("男士有:");
    print_queue(man);
    printf("\n");
    printf("女士有:");
    print_queue(woman);
    printf("\n");
    match(&man,&woman);
    if(IsNull(man)!=0)
    {
        left(man);
    }
    else
        if(IsNull(woman)!=0)
        {
            left(woman);
        }
        else
        {
            printf("男士和女士全部找到舞伴!\n");
        }
}
2010-03-01 12:40
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
收藏
得分:0 
回复 5楼 小J
谢啦
2010-03-02 19:39
小兔子慢慢
Rank: 2
等 级:论坛游民
帖 子:45
专家分:30
注 册:2009-4-13
收藏
得分:0 
回复 4楼 小J
DataType dequeue(cirqueue *Q)
{DataType temp;
    if(isempty(Q))
    {printf("duikong");
    exit(1);



    }

Q->count --;
temp=Q->data [Q->front ];
Q->front =(Q->front +1)%queuesize;


return temp;

}



这个是我在书上看的代码

你能不能把主函数的东西给我改改



2010-03-03 21:33
快速回复:舞伴问题 帮我看看 错在哪里
数据加载中...
 
   



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

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