zoukankan      html  css  js  c++  java
  • c#递归实现螺旋数组

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication5
    {
    class Program
    {
    public static int[,] a = new int[7, 7];
    public static int count = 0;
    public static int row = 0;
    public static int col = 0;
    public static int RowMax = 6;
    public static int RowMin = 0;
    public static int ColMax = 6;
    public static int ColMin = 0;
    public static int shangzuo1 = 0;

    public static bool c = false;
    public static int p = 0;
    public static int q = 0;
    static void Main(string[] args)
    {
    digui();
    int n = 7;
    if(n%2!=0)
    a[n / 2, n/ 2] = n*n;
    for (int i = 0; i < 7; i++)
    for (int j = 0; j < 7; j++)
    {
    Console.Write(a[i, j] + " ");
    if (j == 6)
    Console.WriteLine();

    }
    Console.ReadLine();
    }

    public static void digui()
    {


    while (p == 0 && q == 0)
    {
    count++;
    if (count > 49)
    return;
    if (c==true)
    {
    col++;
    row++;
    ColMin++;
    ColMax--;
    RowMin++;
    RowMax--;
    c = false;

    }

    if (col > ColMax)
    {

    q = 1;


    col--;
    count--;
    if(count<49)


    digui();


    }
    else
    {

    a[row, col] = count;
    if (count == 49)
    return;

    col++;
    }


    }
    while (p == 0 && q == 1)
    {
    count++;
    if (count > 49)
    return;

    row++;
    if (row > RowMax)
    {

    p = 1;


    row--;
    count--;
    if (count < 49)
    digui();


    }
    else
    {
    a[row, col] = count;
    if (count == 49)
    return;

    }

    }
    while (p == 1 && q == 1)
    {
    count++;

    if (count >49)
    return;
    col--;
    if (col < ColMin)
    {

    q = 0;

    col++;
    count--;
    if (count <49)
    digui();


    }
    else
    {

    a[row, col] = count; if (count == 49)
    return;

    }

    }
    while (p == 1 && q == 0)
    {
    count++;
    if (count >49)
    return;
    row--;

    if (row < RowMin)
    {

    p = 0;
    c = true;

    row++;
    count-=2;
    if (count <49)
    digui();

    }
    else
    {

    if(row>RowMin)
    a[row, col] = count; if (count == 49)
    return;

    }

    }
    }
    }
    }

  • 相关阅读:
    java多线程学习-同步之线程通信
    java多线程学习-同步(synchronized)
    java多线程学习-开篇
    面向对象-多线程-异常机制-查漏补缺
    Sprin2.5+Hibernate3.3+Struts2.0.11集成
    Strut1.3+Sprin2.5+Hibernate3.3集成
    Sprin2.5+Hibernate3.3集成
    Spring学习笔记
    Hibernate学习笔记
    Sping
  • 原文地址:https://www.cnblogs.com/kexb/p/3660381.html
Copyright © 2011-2022 走看看