马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#define ElementType int
typedef struct Node {
ElementType data;
struct Node* next;
} Node, *LinkList;
void InitCreateLinkLoopList(LinkList* L);
void CreateLinkLoopList(LinkList* L, int n);
void Magician(LinkList* L);
void OutPut(LinkList* L);
int main()
{
LinkList* L = (LinkList*)malloc(sizeof(LinkList));
InitCreateLinkLoopList(L);
CreateLinkLoopList(L, 13);
Magician(L);
OutPut(L);
return 0;
}
void InitCreateLinkLoopList(LinkList* L) {
(*L) = (LinkList)malloc(sizeof(Node));
(*L)->data = 13;
(*L)->next = (*L);
}
void CreateLinkLoopList(LinkList* L, int n) {
LinkList p, r;
p = (*L);
for (int i = 0; i < n; i++) {
r = (LinkList)malloc(sizeof(Node));
r->next = p->next;
r->data = 0;
p->next = r;
p = r;
}
}
void Magician(LinkList* L) {
LinkList p, q, r;
p = (*L);
int times = 1;
int number = 1;
while (1) {
for (times = 1 ; times <= number; times++) {
p = p->next;
if (p->data != 0) {
times--;
}
}
p->data = number;
number++;
if (number == 14) {
break;
}
}
}
void OutPut(LinkList* L) {
LinkList p = (*L)->next;
LinkList r = (*L);
while (r != p) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
|