如何使用压入和弹出操作的混合序列打印所有可能的序列
How to print all possible sequences with intermixed sequence of push and pop operation
假设在 LIFO stack.How 上执行压入和弹出操作的混合序列以打印所有可能的序列?我只能判断它是关于递归的。例如,如果给出命令 1 2 3,则输出为
1 2 3
1 3 2
2 1 3
2 3 1
3 2 1
使用GoogleGUAVA的方法https://google.github.io/guava/releases/19.0/api/docs/com/google/common/collect/Collections2.html#orderedPermutations(java.lang.Iterable) to get all possible permutations and then for each permutation reverse the order using https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#reverse(java.util.List)
假设在 LIFO stack.How 上执行压入和弹出操作的混合序列以打印所有可能的序列?我只能判断它是关于递归的。例如,如果给出命令 1 2 3,则输出为
1 2 3
1 3 2
2 1 3
2 3 1
3 2 1
使用GoogleGUAVA的方法https://google.github.io/guava/releases/19.0/api/docs/com/google/common/collect/Collections2.html#orderedPermutations(java.lang.Iterable) to get all possible permutations and then for each permutation reverse the order using https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#reverse(java.util.List)