拉丁方阵显示 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;
}
怎么多一列了?