方案按长度排序向量
我有一个 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与上一个问题 使用合并排序的方案向量 的方式相同
,只需替换
length
与向量长度
。Same way as in your previous question Scheme Vector using merge sorting
just replace
length
withvector-length
.