-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/com/ximo/datastructuresinaction/leetcode/recursive/PrintReverse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.ximo.datastructuresinaction.leetcode.recursive; | ||
|
||
/** | ||
* @author xikl | ||
* @date 2019/6/26 | ||
*/ | ||
public class PrintReverse { | ||
|
||
public static void printReverse(char[] strArray) { | ||
printReverse(0, strArray); | ||
} | ||
|
||
/** | ||
* 递归调用 | ||
* | ||
* @param index 索引 | ||
* @param strArray 原始数组 | ||
*/ | ||
private static void printReverse(int index, char[] strArray) { | ||
if (strArray == null || index > strArray.length) { | ||
return; | ||
} | ||
|
||
// 我们假设先执行后面的 | ||
printReverse(index + 1, strArray); | ||
// 然后再执行自己 | ||
System.out.println(strArray[index]); | ||
} | ||
|
||
|
||
} |