求一蛇形矩阵的c++源程序

来源:百度知道 编辑:UC知道 时间:2024/05/25 14:55:33
例如 输入4
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16

我空间上就有一个啊,给你看看吧
#include <iostream.h>
#include <iomanip.h>
/*
Array 要填充的数组
dir 数据递增方向,以从右上方到左下方为正方向,反之为负方向
index 下标 x+y 的值,顺便说下,x表示行,y表示列
start 该行起始数字
len 该行总共几个数字
line 第几行
NUM 方阵的阶次,即行值或列值
*/
void fill(int **Array,bool dir,int index,int start,int len,int line,const int NUM)
{
int x;//起始x
int y;//起始y

if(dir)
{
if(line<=NUM)
{
y=line-1;
x=index-y;
}
else
{
x=line-NUM;
y=index-x;
}
while(len)
{
Array[x++][y--]=start++;
len--;
}

}
else
{
if(lin