鱼C论坛

 找回密码
 立即注册
查看: 3221|回复: 2

约瑟夫问题求助,照着小甲鱼的程序抄的,还是有错

[复制链接]
发表于 2017-8-3 12:51:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<stdlib.h>
typedef struct LNode
{
int data;
struct LNode *next;
}LNode;
typedef struct LNode* LinkList;

LNode* CreateList(int n)
{
LNode *p=NULL,*head;
head=(LinkList)malloc(sizeof(LNode));
p=head;
LNode *s;
int i = 1 ;
for(n != 0)
{
while( i <= n )
        {
        s=(LinkList)malloc(sizeof(LNode));
        s->data=i++;
        p->next=s;
        p=s;
        }       
s->next=head->next;
}
return s->next;
}



int main()
{
        int n=41;
        int m=3;
        int i;
        LNode *p=CreateList(n);
        LNode *temp;
        m=m%n;
        while(p!=p->next)
        {
        for(i=1;i<m-1;i++)
        {
        p=p-> next;
        }
        printf("%d",p->next->data);
       
        temp=p->next;
        p->next=temp->next;
        free(temp);
        p=p->next;

        }
        printf("%d",p->data);
return 0;

}


--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.c
C:\Users\LSZ\Desktop\1.c(15) : error C2275: 'LNode' : illegal use of this type as an expression
        C:\Users\LSZ\Desktop\1.c(7) : see declaration of 'LNode'
C:\Users\LSZ\Desktop\1.c(15) : error C2065: 's' : undeclared identifier
C:\Users\LSZ\Desktop\1.c(16) : error C2143: syntax error : missing ';' before 'type'
C:\Users\LSZ\Desktop\1.c(17) : error C2143: syntax error : missing ';' before ')'
C:\Users\LSZ\Desktop\1.c(17) : error C2143: syntax error : missing ';' before ')'
C:\Users\LSZ\Desktop\1.c(17) : warning C4552: '!=' : operator has no effect; expected operator with side-effect
C:\Users\LSZ\Desktop\1.c(19) : error C2065: 'i' : undeclared identifier
C:\Users\LSZ\Desktop\1.c(21) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct LNode *'
C:\Users\LSZ\Desktop\1.c(22) : error C2223: left of '->data' must point to struct/union
C:\Users\LSZ\Desktop\1.c(23) : warning C4047: '=' : 'struct LNode *' differs in levels of indirection from 'int '
C:\Users\LSZ\Desktop\1.c(24) : warning C4047: '=' : 'struct LNode *' differs in levels of indirection from 'int '
C:\Users\LSZ\Desktop\1.c(26) : error C2223: left of '->next' must point to struct/union
C:\Users\LSZ\Desktop\1.c(28) : error C2223: left of '->next' must point to struct/union
C:\Users\LSZ\Desktop\1.c(28) : warning C4033: 'CreateList' must return a value
执行 cl.exe 时出错.

1.exe - 1 error(s), 0 warning(s)

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-8-3 13:16:47 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-4 11:53:36 | 显示全部楼层
17行,for改成if, l另外 printf("%d",p->next->data);最好加个空格
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 14:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表