0

我有一个 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
4

1 回答 1

1

与上一个问题Scheme Vector 中使用合并排序的方式相同

只需替换lengthvector-length.

于 2011-10-24T21:33:20.197 回答