鱼C论坛

 找回密码
 立即注册

循环链表实现拉丁方程

已有 190 次阅读2019-8-20 10:19


#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int data ;
    struct node *next ;
} node ;

node *create (node *head , int rank)
{
    head = (node *)malloc(sizeof(node));
    node *tmp = head ;
    node *add = NULL ;
    for (int i = 0 ; i < rank ; i++)
    {
        add = (node *)malloc(sizeof(node));
        add->data = i+1 ;
        tmp->next = add ;
        tmp = add ;
    }
    add->next = head->next ;
    free(head);
    return add->next ;
}

int main ()
{
    node *head = NULL ;
    node *output = NULL ;
    node *tmp = NULL ;
    int rank ;
    printf("please input the rank of latin square: \n");
    scanf("%d",&rank);
    head = create(head , rank);
    output = head ;
    tmp = output ;
    for (int j = 0 ; j < rank ; j++)
    {
        output = tmp ;
        for (int k = 0 ; k < rank ; k++)
        {
            printf("%d  ",output->data);
            output = output->next ;
        }
        tmp = tmp->next ;
        printf("\n");
    }
    return 0 ;
}

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 08:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部