点击这里给我发消息 点击这里给我发消息

一个JOSEPH环的程序

添加时间:2013-12-7
    相关阅读: 程序

      #include<stdio.h>
    typedef strUCt Node
    {
     int number;
     int cipher;
     struct Node *next;
    }node,*hu;
    hu H;//定义头结点为H;
    init(int n)
    {
      int i;
      int cipher;
      hu L;
      if(n>=1)
      {
        scanf("%d",&cipher);
        H=(hu)malloc(sizeof(node));//生成头结点;
        H->number=1;
        H->cipher=cipher;
        H->next=H;
        for(i=1;i<n;i++)
        {
          scanf("%d",&cipher);
          L=(hu)malloc(sizeof(node));//生成副结点;
          L->number=i+1;
          L->cipher=cipher;
          L->next=H->next;
          H->next=L;
          H=L;
        }
        H=H->next;//循环单链表的生成;
      }
      else
        printf("The N's value that you inputted is invalid!");
    }
    Joseph(int m,hu h)//进行程序的循环,使顺序出列;
    {
      int i;
      hu l;
      l==h;
      i=1;
      while(i!=m)
      {
        i=i+1;
        l=h;
        h=h->next;
      }
      printf("%3d",h->number);
      m=h->cipher;
      l->next=h->next;
      free(h);
      h=l->next;
      if(h!=l)
        Joseph(m,h);
      else
      {
        printf("%3d",h->number);
        free(h);
      }
    }
    main()
    {
     int m;
     int n;
     int i;
     clrscr();
     printf("Please input the starting value of M ( the upper limit worth of M ) : ");
     scanf("%d",&m);
     printf("Please input the man's figure who have a hand in: ");
     scanf("%d",&n);
     printf("Please input the cipher from number1 to number%d:",n);
     init(n);
     printf("The order of Dequeue is :");
     Joseph(m,H);
    }

 

相关一个JOSEPH环的程序

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册