码迷,mamicode.com
首页 > 其他好文 > 详细

002 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin

时间:2017-09-16 11:50:57      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:span   ott   nod   eof   hat   col   bottom   new   def   

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

标签:span   ott   nod   eof   hat   col   bottom   new   def   

原文地址:http://www.cnblogs.com/Shareishappy/p/7529891.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!