002 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin
Posted ReedyLi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了002 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin相关的知识,希望对你有一定的参考价值。
000--Magic Poker
Put the poker with specific sequence, so that they can show as below:
count 1, open the first card as A, count 2, the first one place to bottom and open the second one as 2; for 3, the first 2 cards put to the bottom, and open the third one 3 ......
#include <stdio.h>
#include <stdlib.h>
#define CardNumber 13
typedef struct node
{
int data;
struct node *next;
}sqlist, *linklist;
linklist CreateLinkList()
{
linklist head = NULL; //the head node with NULL
linklist s, r;
int i;
r = head;
for(i=1;i<=CardNumber;i++)
{
s = (linklist)malloc(sizeof(sqlist));
s->data = 0;
if(head==NULL)
head = s; // for the first newly create node, it becomes head now. the next time, head = o.
else
r->next = s;
r = s;
}
r->next = head; //the last node points to the first node=head
return head;
}
//count the sequence for distributing the card
void Magician(linklist head)
{
linklist p;
int j;
int Counter = 2;
p=head;
p->data = 1; //the first card as 1
while(1)
{
for(j=0;j<Counter;j++)
{
p=p->next;
if(p->data!=0)
{
p->next;
j--;
}
}
if(p->data == 0)
{
p->data = Counter;
Counter++;
if(Counter==14)
break;
}
}
}
void DestroyList(linklist* list)
{
free(list);
}
int main()
{
linklist p;
int i;
p = CreateLinkList();
Magician(p);
printf("please set the card with the sequece as below: \n");
for(i=0;i<CardNumber;i++)
{
printf("card%d", p->data);
p=p->next;
}
DestroyList(&p);
return 0;
}
001-- Latin print
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
}sqlist, *linklist;
linklist CreateLinkList()
{
linklist head = NULL;
linklist s,r;
int i,n ;
printf("please input the latin Number you want to create: ");
scanf("%d\n", &n);
r = head;
for(i=1;i<=n;i++)
{
s = (linklist)malloc(sizeof(sqlist));
s->data = i;
if(head==NULL)
head=s;
else
r->next = s;
r=s;
}
r->next = head;
return head;
}
void PrintLatin(linklist head)
{
linklist p,q;
int i,j,n;
printf("please input the latin Number you want to create: ");
scanf("%d\n", &n);
q=p=head;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d",p->data);
p = p->next;
}
printf("\n");
q = q->next;
p = q;
}
}
int main()
{
linklist p;
p=CreateLinkList();
PrintLatin(p);
return o;
}
以上是关于002 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin的主要内容,如果未能解决你的问题,请参考以下文章
002 -- Circle LinkList_Josephus Story
001 -- Circle LinkList, list initiate, add a new node, delete a node, and List traverse
Android 开发也要懂得数据结构 - LinkList源码
初识OpenCV-Python - 002: Drawing functions