利用循环队列实现舞伴配对

#ifndef _CYCLELINE_H_

#define _CYCLELINE_H_

#endif     

#include<stdlib.h>

#include <string.h>           

#include “stdio.h”

#include “math.h”

#define MaxSize  100

typedef int status;

typedef char DataType;

typedef struct

{

    

    DataType name[20];

    

 }Line1;

 

typedef struct

{

    Line1 LinSize[MaxSize];

    

    int rear;

    

    int count;

    

    int top;

    

 }Line;

 

 

 

 void InitLin (Line *s)

 

 {

     s->rear=s->top=s->count=0;

     

 }

 

    

   status InsertWLin (Line *s)

   {

       

       char w[20];

    

    int n1;

    

    int i;

       

       if (s->count>MaxSize&&s->rear==s->top)

       

       return 0;

       

              

   }

   

    status  DeleLin (Line *s)

   {

       

       

       if (s->count==0&&s->rear==s->top)

       

       return 0;      

   }

   

   

   

    status InsertMLin (Line *s)

   {

    

    char m[20];

    

    int n2;

    

    int i;

       

       if (s->count>0&&s->rear==s->top)

       

       return 0;

       

   }

   

 

 status DestoryLin (Line *s)

 {

 

     free (s);

     

 }

 

#include <stdio.h>
#include “CycleLine.h”
#define MaxSize  100
#include <stdlib.h>
#include <string.h>  

typedef int status;

typedef char DataType;

int main ()
{
    
    Line p,q;
    
    p.rear=p.top=p.count=0;
    
    q.rear=q.top=q.count=0;
    
    int i,j,num=0,n1=0,n2=0;
    
    char x,y;
    
    char w[20];
    
    char m[20];
    
    
    
    printf (“\nplease input the number of lady for dancing party!\n”);
    
    scanf (“%d”,&n1);
    
      printf (“\nplease input ladies for dancing party!\n”);    
    
    for (i=0;i<n1;i++)
    
    {
        scanf (“%s”,&p.LinSize[p.rear].name);
        
        //p.LinSize[p.rear]=*p.name;
        
         p.rear=(p.rear+1)%MaxSize;
        
          p.count++;
        
        //InsertLin (&p,w[i]);
    
    }
    
    printf (“\nplease input the number of man for dancing party!\n”);
    
    scanf (“%d”,&n2);
    
    printf (“\nplease input man for dancing party!\n”);    
    
    for (i=0;i<n2;i++)
    
    {
        
    scanf (“%s”,&    q.LinSize[q.rear].name);
    
    //q.LinSize[q.rear]=*q.name;
    
     q.rear=(q.rear+1)%MaxSize;
    
      q.count++;
        
    //InsertLin (&p,w[i]);
    
    }
    
    
   /*
    InsertWLin (&p);
    
    p.count++;
    
    InsertMLin (&q);
    
    q.count++;
    */
    
    if (p.count>q.count)
    
    num=q.count;
    
    else
    
    num=p.count;
    
    printf (” \n%d  %d\n”,p.count,q.count);
    
    printf (” \n%d\n”,num);
    
    printf (” \nThe arrange :\n”);
    
    for (j=0;j<num;j++)
    {
        
        
        DeleLin (&p);
        
        p.count–;
        
        DeleLin (&q);
        
        q.count– ;
        
        printf (“\n%s/%s\n”,p.LinSize[p.top].name,q.LinSize[q.top].name);
        
        p.top=(p.top+1)%MaxSize;
        
        q.top=(q.top+1)%MaxSize;
        
    }
    
    
       if (p.count>q.count)
       
       printf (“\nI am sorry ladies ,please wait for another dancing!”);
       
       else  if (p.count==q.count)
       
        printf (“\nAll the people are dancing!”);
        
         else  if (p.count<q.count)
       
        printf (“\nI am sorry gentlemen ,please wait for another dancing!”);
    
    return 0;
    
}

    原文作者:舞伴问题
    原文地址: https://blog.csdn.net/qq_39234304/article/details/79981172
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞