C语言,帮忙检查一下错误~~~(约瑟夫环问题)

来源:百度知道 编辑:UC知道 时间:2024/05/24 15:31:04
#define n 10 /*总人数*/
#define s 1 /*从第几个人*/
#define m 2 /*数几的人出列*/
#define OK 1
#define NULL 0
#define OVERFLOW 0
#define LIST_INIT_SIZE 100
#define LISTINTERMENT 10
typedef int ElemType;
typedef int status;
typedef struct{ /*顺序表存储结构*/
ElemType *elem;
int length;
int listsize;
}Sqlist;
typedef struct LNode{/*循环链表存储结构*/
ElemType data;
struct LNode *next;
}LNode,*Linklist;
status InitList_Sq(Sqlist *Sq){ /*初始化顺序表*/
Sq->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
Sq->length = 0;
Sq->listsize = LIST_INIT_SIZE;
return OK;
}
status initlist(Linklist *L){ /*初始化圆桌上的人*/
int i;Linklist p,q;
(*L)=(Linklist)malloc(sizeof(LNode));
(*L)->next=NULL;
p=(Linklist)malloc(sizeof(LNode));
p->data=1;
p->next=(*L);
(*L)->next=p;
for(i=2;i<=n;i++)

你这个代码写的太乱了~~~

我粗略帮你调试了一下

代码最开头你连头文件也没有~~

1.加上头文件

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>

2.你在creat_Sq函数里用了insert函数 而Insert_Sq函数此时还未声明

所以在creat_Sq前面加上Insert_Sq函数的声明

status Insert_Sq(Sqlist *Sq,ElemType x);

3.你的insert_Sq函数没有返回值

加上return OK;

这样改了以后就没有错误 编译通过 不过似乎运行时有问题 应该是你的creat——sq函数算法写错了

改正后的
==================================================================
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define n 10 /*总人数*/
#define s 1 /*从第几个人*/
#define m 2 /*数几的人出列*/
#define OK 1
#define NULL 0
#define OVERFLOW 0
#define LIST_INIT_SIZE 100
#define LISTINTERMENT 10
typedef int ElemType;
typedef int status;
typedef struct{ /*顺序表存储结构*/
ElemType *elem;
int length;
int listsize;
}Sqlist;