我程序中用到的第一个递归算法
生活随笔
收集整理的這篇文章主要介紹了
我程序中用到的第一个递归算法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
說來慚愧,工作這么久了都沒有用到一個遞歸算法。呵呵,第一次。
功能介紹:有這樣一個表,自外連接,也就是parent(父結點)所對應的ID也是本表的,這段代碼將返回所有某個節點的子節點ID。
參數介紹:
String deptId:當前的ID
List ids:當前ID下的所有子節點列表
調用:this.getAllSubDeptid(categoryId, categoryIds);
public void getAllSubDeptid(String deptId, List ids) throws SecuritySQLException {
ids.add(deptId);
// 查詢出當前部門的子部門
Map map = new HashMap();
map.put("parent", deptId);
List list =(List) categoryDao.queryByFilter(map);
// 如果子部門數為0,則返回
if (list.size() == 0) {
} else {
for (int i = 0; i < list.size(); i++) {
Category category = (Category) list.get(i);
String subId = (String) category.getId();
getAllSubDeptid(subId, ids);
}
}
}
功能介紹:有這樣一個表,自外連接,也就是parent(父結點)所對應的ID也是本表的,這段代碼將返回所有某個節點的子節點ID。
參數介紹:
String deptId:當前的ID
List ids:當前ID下的所有子節點列表
調用:this.getAllSubDeptid(categoryId, categoryIds);
public void getAllSubDeptid(String deptId, List ids) throws SecuritySQLException {
ids.add(deptId);
// 查詢出當前部門的子部門
Map map = new HashMap();
map.put("parent", deptId);
List list =(List) categoryDao.queryByFilter(map);
// 如果子部門數為0,則返回
if (list.size() == 0) {
} else {
for (int i = 0; i < list.size(); i++) {
Category category = (Category) list.get(i);
String subId = (String) category.getId();
getAllSubDeptid(subId, ids);
}
}
}
總結
以上是生活随笔為你收集整理的我程序中用到的第一个递归算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查看、关闭被占用的端口
- 下一篇: oracle中用START WITH..