⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄

📁 c 的一些经典算法,满好的,适合初学者. 也可以当作小程序看,对初学者会很有帮助
💻
字号:
#include <stdlib.h>
#include <stdio.h>
typedef struct node
{
 int data;
 struct node *next;
}LNode;

main()
{
 LNode* Create(int,int);
 LNode* GetNode(LNode *);
 int Print(LNode *,int);
 LNode *p;
 int n,k,m;
 do{
  printf ("Input the total number of people:"); /*输入总人数*/
  scanf ("%d",&n);
   }while (n<=0);
 do{
  printf ("Input the first person's numeber:",n);  /*输入开始人的序号(1~%d)*/
  scanf ("%d",&k);
   }while (k<=0 || k>n);
 do{
  printf ("Input the interval number:"); /*输入间隔数字*/
  scanf ("%d",&m);
   }while(m<=0);

 p=Create(n,k);
 Print(p,m);
 printf("Press any key to quit!");
 getch();
 return 0;
}

LNode* Create(int n,int k)/*创建循环链表*/
{
 int start=k-1;
 LNode *s,*p,*L=0,*t;
 if (start==0) start=n;
 while (n!=0)
 {
  s=(LNode *)malloc(sizeof(LNode));
  if (L==0) p=s;
  if (n==start) t=s;
  s->data=n;
  s->next=L;
  L=s;
  n--;
 }
 p->next=L;
 return t;
}

LNode* GetNode(LNode *p)/*出队函数*/
{
 LNode *q;
 for (q=p;q->next!=p;q=q->next);
 q->next=p->next;
 free (p);
 return (q);
}

Print(LNode *p,int m)/*输出函数*/
{
 int i;
 printf ("out line:\n");  /*出队编号*/
 while (p->next!=p)
 {
  for (i=1;i<=m;i++)
   p=p->next;
  printf ("%d ",p->data);
  p=GetNode(p);
 }
 printf("%d\n",p->data);
 return 0;
}

 
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -