这个程序错在哪里了(C语言)请高手指点~谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/16 03:32:58
题目:
1、杀人游戏:n个人围成一圈,编号为1,2,3,...,n,从1号开始按顺时针,数到第x的那个人离开,下一个从1开始数。如此继续,问最后剩下的一个人的编号是几?分别以 顺序存储结构 及 链表结构 实现。n 和 x 由用户在运行时输入。

用链表结构运行:
# include <stdio.h>
# include <stdlib.h>
# define ElemType char
typedef struct Node
{
ElemType data;
struct Node *next;
}Node,* Linklist;

// **************************************************
void InitList(Linklist *L)
{
* L=(Linklist)malloc(sizeof(Node));
(*L)->next=NULL;
}

//**************************************************
void CreateFromTail(Linklist L,Linklist rear)
{
Node *s,
int flag = 1;
char c;
rear=L;
printf("Enter the number of peopele(遇回车输入结束):\n");
while(flag)
{
scanf("%s",&c);
if (c!='\n')

{
s=(Node *)malloc(sizeof(Node));

错误很多,我挨个改完了之后,虽然没有错误了,报了两个警告,但是最重要的是,我都不知道程序要干什么了,我都没敢运行,怕崩溃,你自己对照一下吧,语法错误很多,首先改语法,然后按照你自己的意思,再改内容吧。
# include <stdio.h>
# include <stdlib.h>
#include<iostream>
using namespace std;
# define ElemType char
typedef struct Node
{
ElemType data;
struct Node *next;
}Node,* Linklist;

// **************************************************
void InitList(Linklist L)
{
L=(Linklist)malloc(sizeof(Node));
(L)->next=NULL;
}

//**************************************************
void CreateFromTail(Linklist L,Linklist rear)
{
Node *s;
int flag = 1;
char c;
rear=L;
printf("Enter the number of peopele(遇回车输入结束):\n");
while(flag)
{
scanf("%s",&c);
if (c!='\n')

{
s=(Node *)malloc(sizeof(Node));
s->data=c;
rear->ne