#include<stdio.h>
#include<string.h>
#include<cstdlib>
struct linklist{
int a;
struct linklist *next;
};//自定义节点;
struct linklist *create(){
struct linklist *headnode=(struct linklist*)malloc(sizeof(struct linklist));
headnode->next=NULL;
headnode->a=100;
return headnode;
}//创建表
struct linklist *print(int data,struct linklist *headnode){
struct linklist *connect=(struct linklist*)malloc(sizeof(struct linklist));
connect->a=data;
connect->next=headnode;
return connect;
}//创建节点
//头插法
void insertnodebyhead(int data,struct linklist *headnode){
struct linklist *new=print(data,headnode);
new->next=headnode->next;
headnode->next=new;
}
//尾插法
void insertnodebytail(struct linklist *headnode,int data){
struct linklist *new=print(data,headnode),*tailnode;
tailnode=headnode;
while(tailnode->next!=headnode){
tailnode=tailnode->next;
}
tailnode->next=new;
new->next=headnode;
}
int length(struct linklist*joe){
int length=1;
struct linklist *k;
k=joe;
while(k->next!=joe)
{length++;
k=k->next;
}
return length;
}
int main(){
struct linklist *p,*headnode,*joe,*kill;
int n,m,k=0,length1,i;
printf("请输入n和m");
scanf("%d%d",&n,&m);
headnode=create();
p=headnode;
for(i=0;i<n;i++)
{struct linklist *node;
node=print(i+1,headnode);
p->next=node;//链接
p=node;
}
p->next=headnode->next;
free(headnode);
joe=p->next;
length1=length(joe);
while(length1!=1){
k++;
if(k==m-1)
{kill=joe->next;
joe->next=kill->next;
free(kill);
length1--;
k=0;
}
joe=joe->next;
}
printf("%d",joe->a);}
【相关推荐】
我们再来看一下,平时经常听到的浮点数会有精度损失的情况是怎么回事?
如果我们现在想用浮点数表示 0.2,它的结果会是多少呢?
0.2 转换为二进制数的过程为,不断乘以 2,直到不存在小数为止,在这个计算过程中,得到的整数部分从上到下排列就是二进制的结果。
0.2 * 2 = 0.4 -> 0 0.4 * 2 = 0.8 -> 0 0.8 * 2 = 1.6 -> 1 0.6 * 2 = 1.2 -> 1 0.2 * 2 = 0.4 -> 0(发生循环) ...
所以 0.2(D) = 0.00110…(B)。
因为十进制的 0.2 无法精确转换成二进制小数,而计算机在表示一个数字时,宽度是有限的,无限循环的小数存储在计算机时,只能被截断,所以就会导致小数精度发生损失的情况。