将开发过程经常用到的一些内容片段做个记录,下面内容是关于C语言对约瑟夫链表的简单实现的内容,希望对大家有用处。
#include<stdio.h>
#include<malloc.h>
typedef struct xhlb
{
int data;
}list;
{
int i=1;
head=NULL;
p=q=head;
while(i<n+1)
{
p->data=i;
i++;
if(headNULL)
head=p;
else
q->next=p;
q=p;
}
q->next=head;
return head;
}
int main()
{
int n,m,j=1;
printf(“n=”);
scanf("%d",&n);
printf(“nm=”);
scanf("%d",&m);
printf(“n”);
p=creat_list(n);
q=p->next;
while(p!=p->next)
{
if(j(m-1))
{
printf("%4d",q->data);
q=q->next;
p->next=q;
j=0;
}
p=q;
q=q->next;
j++;
}
printf("%4dn",p->data);
return 0;
}