论坛: 编程破解 标题: 约瑟夫环--刚学数据结构,大家帮忙看看 复制本贴地址    
作者: mmgg00 [mmgg00]    论坛用户   登录
这是我的代码
可是就是不对啊,刚学数据结构,大家帮忙看看,谢谢:)
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
struct list
  {
    int no;
    int data;
    struct list *next;
  };
struct list *creatlist(int n)

  {
    int i,r;
    struct list *p,*head,*q;
    head=(struct list*)malloc(sizeof(struct list));
    q=head;
  for(i=1;i<=n;i++)
    {
      p=(struct list*)malloc(sizeof(struct list));
      p->no=i;
      printf("this is the %d no:",i);
      scanf("%d",r);
      p->data=r;
      q->next=p;
      q=p;
    }
    q->next=head->next;
  free(head);
return (q);
}
main()
{
  int i,n=7,m,j;
  struct list *head,*p,*q;
  head=creatlist(n);
printf("please input m:");
scanf("%d",&m);
i=0;
q=head;
while(p->next!=p)
  {
    for(j=1;j<=n;j++)
    {
      for(i=1;i<m;i++)
      q=q->next;
      p=q->next;
      printf("%d",p->no);
      q->next=p->next;
      m=p->data;
      free(p);}

}
}




地主 发表时间: 04-10-15 20:43

回复: windflower [windflower]   论坛用户   登录
你能把程序的意思说一下吗?

B1层 发表时间: 04-10-16 00:15

回复: gg [gg123]   论坛用户   登录
这是什么数据库呢
不过跟SQL有点像哦

B2层 发表时间: 04-12-02 14:37

回复: taojuntjpp [taojuntjpp]   论坛用户   登录
是C语言版数据结构吧
最好能把一些句子注释出来~~
这样别人也容易看一点呀~~~


B3层 发表时间: 04-12-03 14:58

回复: hackgou [hackgou]   论坛用户   登录
代码完全正确的,只是在构造约瑟夫环的循环中
引用:

scanf("%d",&r);


少了红色的东东。
添加就OK了!

B4层 发表时间: 04-12-06 21:42

回复: NetMelody [mmgg00]   论坛用户   登录
谢谢啦
唉~~~没有写注释的习惯啊

B5层 发表时间: 04-12-07 00:32

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号