方案排序矢量长度

时间:2011-10-24 17:29:27

标签: sorting vector scheme depth-first-search

我有一个dfs方法会返回向量列表,如何根据向量的长度对元素进行排序。

(define (dfs path) ;path store vector index, start from 0 
 (cond
 ((dfsStack' empty?)(newline))
  (else (set! currentPath (dfsStack' pop!))
      (findLast (car currentPath) 0)
      (checkUnvisited (cdr (vector-ref network lastNum)))

      (cond
        ((eq? lastName reach) ;reach point
         (duplicate path)          
         (dfs (+ path 1)) ;continue dfs to find next path         
         )
        ((and (not (eq? lastName reach))(eq? unvisited #t)) ;no more neighbours
         (dfs path)
         ) 
        ((and (not (eq? lastName reach))(eq? unvisited #f)) ;found the neighbours
         (pushStack lastNeighbours currentPath)
         (dfs path)
         )
        );//end cond
      )   
);//end cond
);//end dfs

1 个答案:

答案 0 :(得分:1)

与上一个问题Scheme Vector using merge sorting

相同

只需将length替换为vector-length