#include <stdio.h>
#include <malloc.h>
struct node{
int data;
struct node* next;
};
struct node* Createlist(int n){/*創建一個回圈鏈表*/
struct node* head,*tail,*p;
int i;
head=(struct node*)malloc(sizeof(struct node));
head->data=https://bbs.csdn.net/topics/1;/*頭結點的值域不為空*/
head->next=NULL;
tail=head;
for(i=2;i<=n;i++){
p=(struct node*)malloc(sizeof(struct node));
p->data=https://bbs.csdn.net/topics/i;
p->next=NULL;
tail->next=p;
tail=p;
}
tail->next=head;/*將尾指標指向頭結點,構成回圈鏈表*/
return head;
};
int main(){
int n,k;
struct node* head,*p,*t;
while(scanf("%d",&n)!=EOF&&n!=0){
head=Createlist(n);
for(p=head,k=1;;p=p->next,k++){/*k為標記標量,用來記錄指標走過的結點數*/
if(k%5==0){/*當k對5取余等于0時,要么派出排長,要么刪掉當前結點*/
if(p->data=https://bbs.csdn.net/topics/=1){
printf("%d\n",k/5);
break;
}
else{
t=head;
while(t->next!=p)/*尋找當前結點的前一個結點*/
t=t->next;
t->next=p->next;/*洗掉當前結點*/
}
}
}
}
return 0;
uj5u.com熱心網友回復:
用序號標記一下轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/42750.html
標籤:C++ 語言
上一篇:求助求助
