水手
shuishou119800 · 共 3 篇文章
[置顶] 带条件的排列组合算法分析
算法说明: 用1、2、2、3、4、5这六个数字打印出所有不同的排列,如:512234、412345等。要求:"4"不能在第三位,"3"与"5"不能相连 算法代码: public class PermutationAlgo { private int count = 0; public void calculate(){ String eleStr = "122345"; depthSearch(eleStr, ""); System.out.println("符合条件的总结果数为:"+count+"条"); } /** * @param eleStr - 待分配字符组成的串 * @param…
2009-12-16 13:07 · 算法 · 评论(2)
[置顶] 内螺旋矩阵算法分析
算法说明: 在屏幕上打印如下结果: int i=5; 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 int i=6 1 2 3 4 5 6 20 21 22 23 24 7 19 32 33 34 25 8 18 31 36 35 26 9 17 30 29 28 27 10 16 15 14 13 12 11 算法代码: public class HelixAlgo { public void print(int len){ if(len<=0){ System.out.println("请输入大于0的整…
2009-12-16 12:39 · 算法 · 评论(13)
用桥梁模式实现螺旋矩阵算法
前两天写了一篇文章,分析了“ 内螺旋矩阵算法 ”的实现,讨论到了面向对象编程的可扩展性,于是今天用桥梁模式将代码做了些改造,具体如下: package com.algo; class Position { private int x; private int y; public Position(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } publ…
2009-12-17 21:01 · 算法 · 评论(4)