#include
#include
struct linklist*create(int n);
int find(struct linklist*head,int n,int all);
void freememory(struct linklist*head);
struct linklist
{
int data;
struct linklist*next;
};
int main()
{
struct linklist*head;
int n,num,i;
int answer;
int group;
scanf("%d",&group);
for(i=0;i
{
scanf("%d%d",&n,&num);
if(n>num)
{
head=create(n);
answer=find(head,num,n);
printf("%d\n",answer);
freememory(head);
}
else
printf("%d",n);
}
return 0;
}
struct linklist*create(int n)
{
int i;
struct linklist*p1,*p2,*head;
head=NULL;
p1=p2=malloc(sizeof(struct linklist));
for(i=0;i
{
p1->data=i+1;
if(i==0)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=malloc(sizeof(struct linklist));
}
p2->next=head;
return head;
}
int find(struct linklist*head,int n,int all)
{
int count=0,temp=0,m;
struct linklist*p1,*p2;
p1=p2=head;
while(1)
{
if(p1==head)
count=0;
count++;
if(count%n==0)
{
temp++;
p2->next=p1->next;
free(p1);
p1=p2;
}
if(temp==all-n)
{
p1=p1->next;
m=p1->data;
return m;
}
p2=p1;
p1=p1->next;
}
}
void freememory(struct linklist*head)
{
struct linklist*p1,*p2;
p1=p2=head;
while(p1->next==head)
{
p1=p1->next;
}
p1->next=NULL;
p1=head;
while(p1!=NULL)
{
p2=p1;
p1=p1->next;
free(p2);
}
}
请问我这个程序为什么内存超限
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
0条回答 默认 最新
悬赏问题
- ¥15 求解 yolo算法问题
- ¥15 虚拟机打包apk出现错误
- ¥30 最小化遗憾贪心算法上界
- ¥15 用visual studi code完成html页面
- ¥15 聚类分析或者python进行数据分析
- ¥15 逻辑谓词和消解原理的运用
- ¥15 三菱伺服电机按启动按钮有使能但不动作
- ¥15 js,页面2返回页面1时定位进入的设备
- ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
- ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。