| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1063 人关注过本帖
标题:[求助]约瑟夫环程序没错误但在C++6.0下运行不了清大家指点谢谢
取消只看楼主 加入收藏
西牛616
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-4-6
收藏
 问题点数:0 回复次数:0 
[求助]约瑟夫环程序没错误但在C++6.0下运行不了清大家指点谢谢

#include "malloc.h"
#include "stdio.h"
#define MAX 100
#define ERROR 0
#define OK 1
typedef int ElemType;
typedef struct LNode
{
int num;
ElemType data;
struct LNode *next;
}LNode;
LNode *head,*this,*new;
int str[MAX];
new_code(int a);
delete_code(int a,int b);

main()
{
int m,n,i;
printf("Enter the first code (m):");
scanf("%d",&m);
printf("\nEnter the people number (n):");
scanf("%d",&n);
getchar();
printf("\n");
new_code(n);
if(head!=NULL)
delete_code(n,m);
else
{
printf("list is empty\n");
exit(0);
}
for(i=0;i<n;i++)
printf("%3d",str[i]);
printf("\n");
}
new_code(int a)
{
int i=1;
char numstr[10];
new=(LNode *)malloc(sizeof(LNode));
if(new==NULL)
return ERROR;
if(head==NULL)
head=new;
this=head;
while(--a!=0)
{
this->num=i;
printf("enter the %d code(data):",i);
gets(numstr);
this->data=atoi(numstr);
new=(LNode *)malloc(sizeof(LNode));
this->next=new;
this=new;
i++;
}
this->num=i;
printf("enter the %d code(data):",i);
gets(numstr);
this->data=atoi(numstr);
this->next=head;
return OK;
}
delete_code(int a,int b)
{
int i;
int j=0;
LNode *p;
while((a--)!=1)
{
for(i=1;i<b;i++)
{
p=this;
this=this->next;
}
b=this->data;
str[j]=this->num;
p->next=this->next;
free(this);
j++;
}
str[j]=this->next->num;
return OK;
}

这个程序编译没问题,但运行不了,请教高手指点,谢谢

搜索更多相关主题的帖子: 约瑟夫 运行 
2006-04-06 17:14
快速回复:[求助]约瑟夫环程序没错误但在C++6.0下运行不了清大家指点谢谢
数据加载中...
 
   



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

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