酸菜鱼爱吃柿子 2018-04-24 01:46 采纳率: 0%
浏览 1237
已结题

C语言约瑟夫环顺序表,帮忙改错,谢谢

#include
#include
typedef int DataType;
typedef PSeqList;
void josephus_seq(PSeqList palist,int s,int m)
{
int s1,i,w;
s1=s-1;
for(i=palist->n;i>0;i--)
{
s1=(s1+m-1)%i;
w=palist->element[s1];
printf("out element %d\n",w);
deleteP_seq(palist,s1);
{
int q;
if(s1palist->n-1)
{
printf("Not exist!\n");
return 0;
}
for(q=s1;qn-1;q++)
palist->n=palist->n-1;
return 1;
}
}
}
main()
{
PSeqList jos_alist;
int i;
int n,s,m;
printf("\n please input the value of n=");
scanf("%d",&n);
printf("please input the values of s=");
scanf("%d",&s);
printf("please input the values of m=");
scanf("%d",&m);
jos_alist=createNullList_seq(n);
{
jos_alist palist=(jos_alist)malloc(sizeof(struct SeqList));
if(palist!=NULL)
{
pslist->element=(DataType*)malloc(sizeof(DataType)*m);
if(palist->element)
{
palist->maxnum=m;
palist->n=0;
return palist;
}
else free(palist);
}
printf("Out of space!!\n");
return NULL;
}
if(jos_alist!=NULL)
{
for(i=0;i insertpre_seq(jos_alist,i,i+1);
{
int q;
if(palist->n>=palist->maxnun)
{
printf("Overflow!\n");
return 0;
}
if(pn)
{
printf("Not exist!\n");
return 0;
}
for(q=palist->n-1;q>=p;q--)
palist->element[q+1]=palist->element[q];
palist->element[p]=x;
palist->n=palist->n+1;
return 1;
}
josepjus_seq(jos_alist,s,m);
free(jos_alist->element);
free(jos_alist);
}
}
图片说明

  • 写回答

4条回答 默认 最新

  • threenewbee 2018-04-24 02:11
    关注

    typedef PSeqList; 这个定义呢?代码不全,把struct SeqList的定义先补上

    main() 这个怎么连返回值都没有,你这个是turbo c的写法

    if(s1palist->n-1) 这里s1后面少运算符

    错误太多了,你要是实在不会,搜索个现成的抄抄吧。

    评论

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline