| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 978 人关注过本帖
标题:如何把这个算法转换成可以被计算机执行的程序?
取消只看楼主 加入收藏
丝袜脚掌
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-8-18
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
如何把这个算法转换成可以被计算机执行的程序?
   typedef struct{
           char name[20];
           char sex;  //性别,'F'表示女性,'M'表示男性
       }Person;
       typedef Person DataType;  //将队列中元素的数据类型改为Person
        
       void DancePartner(Person dancer[],int num)
       {//结构数组dancer中存放跳舞的男女,num是跳舞的人数。
            int i;
            Person p;
            CirQueue Mdancers,Fdancers;
            InitQueue(&Mdancers);//男士队列初始化
            InitQueue(&Fdancers);//女士队列初始化
            for(i=0;i<num;i++){//依次将跳舞者依其性别入队
                 p=dancer[i];      
                 if(p.sex=='F')
                     EnQueue(&Fdancers.p);   //排入女队
                 else
                     EnQueue(&Mdancers.p);   //排入男队
             }
             printf("The dancing partners are: \n \n");
             while(!QueueEmpty(&Fdancers)&&!QueueEmpty(&Mdancers)){
                   //依次输入男女舞伴名
                   p=DeQueue(&Fdancers);     //女士出队
                   printf("%s        ",p.name);//打印出队女士名
                   p=DeQueue(&Mdancers);     //男士出队
                   printf("%s\n",p.name);    //打印出队男士名
             }
             if(!QueueEmpty(&Fdancers)){ //输出女士剩余人数及队头女士的名字
                   printf("\n There are %d women waitin for the next  round.\n",Fdancers.count);
                   p=QueueFront(&Fdancers);  //取队头
                   printf("%s will be the first to get a partner. \n",p.name);
              }else
                  if(!QueueEmpty(&Mdancers)){//输出男队剩余人数及队头者名字
                         printf("\n There are%d men waiting for the next   round.\n",Mdacers.count);
                         p=QueueFront(&Mdancers);
                         printf("%s will be the first to get a partner.\n",p.name);
                   }
        }//DancerPartners  
搜索更多相关主题的帖子: 计算机 算法 
2010-08-18 14:08
快速回复:如何把这个算法转换成可以被计算机执行的程序?
数据加载中...
 
   



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

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