标题:拉丁方阵显示 N*N 用链表怎么实现
只看楼主
hg654321free
Rank: 1
等 级:新手上路
帖 子:15
专家分:5
注 册:2013-4-20
 问题点数:0 回复次数:0 
拉丁方阵显示 N*N 用链表怎么实现
#include <stdio.h>
#include <stdlib.h>

#define  CardNumber 9

typedef struct node
{
    int data;
    struct node *next;
}sqlist, *linklist;

linklist CreateLinkList()
{
    linklist head = 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;
        else
            r->next = s;

        r = s;
            
    }

    r->next = head;

    return head;
}

// 链表拉丁排序
void Magician(linklist head)
{
    linklist p;
    int i;
    int j;
    int Countnumber = 9;

    p = head;
    p->data = 1;  //第一个数是1

    for(i=1;i<Countnumber;i++)
    {
            for(j=i; j <= Countnumber+i; j++)
        {

              p = p->next;
     /*       if(p->data != 0)  //该位置有数,则下一个位置
            {
                p->next;
                j--;
            }*/
        p->data=(j-1)%Countnumber+1;
    //    printf("%3d",(j-1)%Countnumber+1);

          }
      printf("\n");
 
    /*    if(p->data == 0)
        {
            p->data = (j-1)%Countnumber+1;
            Countnumber ++;

            if(Countnumber == 14)
                break;
        }*/
    }
}

 

int main()
{
    linklist p;
    int i;
    int j;
    p = CreateLinkList();
    Magician(p);

    printf("按如下顺序排列:\n");
    for (i=1; i < CardNumber; i++)
    {
    for(j=i;j<=CardNumber+i;j++)
    {
        printf("%3d", p->data);
      p = p->next;
    }
    printf("\n");
    }

 

    return 0;
}

怎么多一列了?
搜索更多相关主题的帖子: next include 
2013-05-01 21:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-406039-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.389302 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved