C循环链表拉丁方阵问题

《C循环链表拉丁方阵问题》

输入n阶 拉丁方阵,

输入第一行的元素,自动算出其他(n-1)行的元素代码很简单

用一个循环链表解决

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct node
  4. {
  5.     int data;
  6.     struct node *next;
  7. };
  8.  
  9. int main ()
  10. {
  11.     node *head;
  12.     head = (node*)malloc(sizeof(node));
  13.     int n;
  14.     printf(“请输入N阶拉丁方阵的N:\n”);
  15.     scanf(“%d”, &n);
  16.     node *p, *q;
  17.     p = head;
  18.     for(int i = 1;<= n; i++)
  19.     {
  20.         q = (node *)malloc(sizeof(node));
  21.         printf(“请输入第一行第%d个数字\n”,i);
  22.         scanf(“%d”,&(q->data));
  23.         p->next = q;
  24.         p = q;
  25.     }
  26.     p->next = head->next;
  27.     p = head->next;
  28.     free(head);
  29.     head = NULL;
  30.  
  31.     for(int i = 0;< n; i++)
  32.     {
  33.         q = p;
  34.         for(int j = 0;< n; j++)
  35.         {
  36.             printf(“%d “,q->data);
  37.             q = q->next;
  38.         }
  39.         printf(“\n”);
  40.         p = p->next ;
  41.     }
  42.     return 0;
  43. }

转自IT博客 :http://www.nightsong.cc

    原文作者:拉丁方阵问题
    原文地址: https://blog.csdn.net/gzw1623231307/article/details/54425207
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞