拉丁方阵问题
原理:
代码:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 9
typedef struct Like
{
int data;
struct Like *next;
}Like, *Likes;
void InitList(Likes *E); //初始化循环链表
void GetList(Likes *E); //创建MAXSIZE个节点(后插)
/*void PutList(Like *E); //调试
void PutList(Like *E) //调试
{
Like *temp = E->next;
do
{
printf("%d", temp->data);
temp = temp->next;
}while(E->next != temp);
}*/
void GetList(Likes *E) //创建MAXSIZE个节点(后插)
{
Like *temp, *tail;
for(int i = 0; i < MAXSIZE; i++)
{
temp = (Likes )malloc(sizeof(Like ));
temp->data = i + 1;
temp->next = (*E)->next;
if((*E)->next == *E)
{
(*E)->next = temp;
}
else
{
tail->next = temp;
}
tail = temp;
}
}
void InitList(Likes *E) //初始化循环链表
{
*E = (Likes )malloc(sizeof(Like ));
(*E)->next = *E;
}
int main()
{
Like *T, *temp;
int Ar;
InitList(&T);
GetList(&T);
temp = T->next;
for(int i = 0; i < MAXSIZE; i++)
{
for(int j = 0; j < MAXSIZE; j++)
{
Ar = temp->data;
temp = temp->next;
}
temp = temp->next;
}
for(int i = 0; i < MAXSIZE; i++)
{
for(int j = 0; j < MAXSIZE; j++)
{
printf("[%d]", Ar);
}
putchar('\n');
}
//PutList(T);
return 0;
}
代码:#include <stdio.h>
#define N 9
int main(){
int arr;
for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) arr = (i + j + 1) % (N + 1);
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++) printf("[%d]", arr);
printf("\n");}
return 0;
}
楼主棒棒
页:
[1]