#include <stdio.h>
#include <stdlib.h>
struct number
{
int shu;
struct number *next;
};
struct number *create(int length)
{
struct number *head;
struct number *p1,*p2;
int i;
p1=p2=(struct number *)malloc(sizeof(struct number));
p1->shu=1;
head=p1;
for(i=2;i<=length;i++)
{
p1=(struct number *)malloc(sizeof(struct number));
p1->shu=i;
p2->next=p1;
p2=p1;
}
p1->next=NULL;
return (head);
}
struct number *del_3(struct number *head,int length)
{
struct number *p,*temp;
int count=2;
p=head;
while(length>1)
{
if(count%3==0)
{
count=1;
temp=p->next;
p->next=temp->next;
free(temp);
p=p->next;
length--;
}
else
p=p->next;
count++;
}
return (p);
}
void print(struct number *p)
{
printf("%d\n",p->shu);
}
int main()
{
int length ;
struct number *head,*p;
printf("input length: ");
scanf("%d",&length);
head=create(length);
p=del_3(head,length);
print(p);
return 0;
}
onemoo
相关分类