当前位置:K88软件开发文章中心编程全书编程全书02 → 文章内容

循环链表-拉丁方阵

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-4 9:09:37

-->

[t]拉丁方阵是一种n×n的方阵,方阵中恰有n种不同的元素,每种元素恰有n个,并且每种元素在一行和一列中 恰好出现一次。[/t]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
  int n;
typedef struct lnode{
  int data;
  struct lnode *next;

}lnode,*linklist;



linklist creat()
{
   linklist head=NULL;
   linklist s,r;
   int i;
   r=head;

  scanf("%d",&n);
  for(i=1;i<=n;i++)
{
   s=(linklist)malloc(sizeof(lnode));
   s->data=i;
   if(head==NULL)
    head=s;
else

   r->next=s;
   r=s;


}
  r->next=head;
  return head;

}

void lading(linklist head)
{
  linklist p=head;
  int i,j=1;
 
while(j<=n)
{
   for(i=1;i<=n;i++)
{
   printf("%4d",p->data);
   p=p->next;
}
printf("\n");
j++;
p=p->next;
 

 }
}

int main()
{
   linklist p=creat();
   lading(p);
   return 0;
}


循环链表-拉丁方阵