拉丁方阵没有源代码。。。。。楼主加油,鱼C加油!我们都看好你哦!
我有 自己写的/************************************************************************/
/* 2015年11月7日11:53:57
功能:实现拉丁方阵
目的:由于是自己写的,那么就是练习一下自己的循环链表的操作与创建.*/
/************************************************************************/
# include<stdio.h>
# include<stdlib.h>
# include<stdbool.h>
typedef struct node
{
int data;
struct node * pNext;
}Node,*pNode;
pNode create_loop_list(int n);
void traverse_loop_list(pNode);
int main(void)
{
//pNode pHead;
int i = 0;
int n = 0;
//int *a = 0;
printf("请输入拉丁方阵的边数:n = ");
scanf("%d", &n);
printf("\n");
pNode pRear = create_loop_list(n);
//traverse_loop_list(pRear);
printf("拉丁方阵如下:\n");
for (i = 0; i < n ; ++i)
{
pRear = pRear->pNext;
traverse_loop_list(pRear);
}
return 0;
}
pNode create_loop_list(int n)
{
//int n = 0;
int i = 0;
int cunt = 0;
pNode pHead = (pNode)malloc(sizeof(Node));
if (NULL == pHead)
{
printf("\a内存分配失败!!");
exit(-1);
}
pNode pTail = pHead;
pTail->pNext = NULL;
//a = &n;
for (i = 0; i < n; ++i)
{
pNode pNew = (pNode)malloc(sizeof(Node));
if (NULL == pNew)
{
printf("\a内存分配失败!!");
exit(-1);
}
pNew->data = i+1 ;
pTail->pNext = pNew;
pNew->pNext = NULL;
pTail = pNew;
}
pNode p = pHead;
pTail->pNext = p->pNext;
//pTail = p->pNext;
free(p);
p = NULL;
return pTail;
}
void traverse_loop_list(pNode pRear)
{
pNode p = pRear;
pNode q = pRear->pNext;
printf("%2d", p->data);
while (p != q)
{
printf("%3d",q->data);
q = q->pNext;
}
printf("\n");
}
/************************************************************************/
/* 在VS2013中程序运行如下:
请输入拉丁方阵的边数:n = 9
拉丁方阵如下:
1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8
请按任意键继续. . . */
/************************************************************************/ xuexi {:9_240:}顶下小甲鱼~ 谢谢小甲鱼老湿{:5_92:} 为什么我觉得第56行的 j--; 应该删掉 Latin方阵代码
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(LinkList)
typedef struct node
{
int data;
struct node *next;
}LinkList;
LinkList *CreatList(int num) //生成循环链表
{
int i;
LinkList *head = NULL;
LinkList *p,*s;
for(i = 1; i <= num; i++)
{
s = (LinkList *)malloc(LEN);
s->data = i;
if(head == NULL)
{
head = s;
}
else
{
p->next = s;
}
p = s;
}
p->next = head;
return head;
}
int main(void)
{
LinkList *p;
LinkList *s;
int num;
int i,j;
printf("请输入想要创建的Latin维数:");
scanf("%d",&num);
p = CreatList(num);
printf("%d维Latin:\n",num);
for(i=0; i < num; i++)
{
for(j=0; j < num; j++)
{
printf("%3d",p->data);
p = p->next;
}
p = p->next;
printf("\n");
}
return 0;
}
页:
1
[2]