首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

索引遍历,递归和非递归算法

2012-10-31 
目录遍历,递归和非递归算法vckbase上那个搜索顺序和递归算法的搜索顺序不同,哥这个就是递归的顺序void sea

目录遍历,递归和非递归算法
vckbase上那个搜索顺序和递归算法的搜索顺序不同,哥这个就是递归的顺序

void search(string file_exp, string folder, reg_exp* rexp==NULL){   if ( !rexp )   {            file1? ==> file[a-zA-Z0-9]{1,1}       file* ==> file[a-zA-Z0-9]{0,}      rexp = new reg_exp("...");   }   foreach(ifile in folder)   {       if ifile is file       {          if rexp.test( ifile ) ret.puch_bach(ifile);       }       else       {          search(file_exp, ifle, rexp)       }   }}// 非递归算法/// 队列加强class queue{    void push_at_end() // 在队列尾部插入    void pop_at_front() // 出队列    void push_at_front(vector)// 在队列插入}// 搜索目录path中文件名符合regexp的文件search_files_at_path(regexp, path){    }// 获取path中所有子目录get_child_paths_at_path(path){}void search_no_recur(v_path, regexp){queue.push_at_end(v_path)while( !queue.empty() ){    curr_path = queue.pop_at_front();    search_files_at_path(regexp, curr_path);    path_vector = get_child_paths_at_path(curr_path);    queue.push_at_front(path_vector);}}

热点排行