Skip to content

Commit 7dd40b3

Browse files
committed
add TestClockwiseOutput
1 parent 6dd2578 commit 7dd40b3

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/main/java/com/chen/algorithms/ArraySort.java renamed to src/main/java/com/chen/algorithm/mergeArray/ArraySort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.chen.algorithms;
1+
package com.chen.algorithm.mergeArray;
22

33
/**
44
* 两个有序数组合并为一个有序数组
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.chen.algorithm.rectangle;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
* User: chenweijie
7+
* Date: 10/16/17
8+
* Time: 11:30 PM
9+
* Description:输入一个矩阵,按照从外向里以顺时针的顺序
10+
* 一次打印出每一个数字 (http://www.cnblogs.com/sunniest/p/4596182.html)
11+
*/
12+
public class TestClockwiseOutput {
13+
14+
15+
@Test
16+
public void test() {
17+
int[][] num = new int[100][100];
18+
int n = 3;
19+
int count = 1;
20+
for (int i = 0; i < n; i++) {
21+
for (int j = 0; j < n; j++) {
22+
num[i][j] = count++;
23+
}
24+
}
25+
output(num, 0, n - 1);
26+
}
27+
28+
29+
public void output(int[][] num, int start, int end) {
30+
31+
if (start > end || end <= 0) {
32+
return;
33+
}
34+
35+
for (int i = start; i <= end; i++) {
36+
System.out.println(num[start][i]);
37+
}
38+
39+
for (int i = start + 1; i <= end; i++) {
40+
System.out.println(num[i][end]);
41+
}
42+
43+
for (int i = end - 1; i >= start; i--) {
44+
System.out.println(num[end][i]);
45+
}
46+
47+
for (int i = end - 1; i > start; i--) {
48+
System.out.println(num[i][start]);
49+
}
50+
51+
output(num, start + 1, end - 1);
52+
53+
}
54+
55+
}

0 commit comments

Comments
 (0)