I have a dfs method will return me list of vectors, How can I sort the elements according to the length of the vector.
(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
Same way as in your previous question Scheme Vector using merge sorting
just replace length
with vector-length
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.