| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 304 人关注过本帖
标题:关于约瑟夫环
只看楼主 加入收藏
tyhk1987
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-11-8
收藏
 问题点数:0 回复次数:0 
关于约瑟夫环

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
const int m=30;
const int n=7;

typedef struct LNode
{
int No;
char Name[10];
int Key;
struct LNode *next;
};//定义一个结点

void output(LNode *);

void main()
{
LNode *L;
LNode *p;
int i;

L=(LNode*)malloc(sizeof(LNode));
if(p=NULL)
{
printf("No enough mermory !");
exit(1);
}
L->next=L; //L为头结点

for(i=n;i>0;i--)
{
p=(LNode *)malloc(sizeof(LNode));
if(p=NULL)
{
printf("no enough mermory !");
exit(1);
}

printf("Input the personel information !");
scanf("%d%s%d",&p->No,&p->Name,&p->Key);
p->next=L->next;L->next=p;
} //定义新结点并插入,从而构造一个链表

void output(LNode *L);//调用输出函数


}


int output(LNode *q)
{
int t, r, k;
int i=0;
r=n;
k=q->Key;
t=k%r;
if(t==0||t==1)
{
for(i=0;i<k-t;i++)
{
q=q->next;
if(q==NULL) return 0;
}
q->next=q->next->next;
q=q->next; k=q->Key; r--;
printf("%d" ,q->No);
}

else
{
for(i=0;i<t-1;i++)
{
q=q->next;
if(q==NULL) return 0;
}
q->next=q->next->next;
q=q->next; k=q->Key; r--;
printf("%d" ,q->No);
}


} //输出函数

请高手帮忙看下哪里出错了???

搜索更多相关主题的帖子: 约瑟夫 
2007-11-08 23:41
快速回复:关于约瑟夫环
数据加载中...
 
   



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

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