CS61B Homework9作业回顾(附代码)

本次作业主要学会运用Disjoin Sets,DisjointSets的class作业已经写好给出。class中两个重要的方法是find和union,find(x)方法返回x的root,并在搜寻过程中递归使用path compression,使得路径上的每个node直接指向root。Union(root1,root2)方法将两个set的root指向其中等级高的那个,else使root1成为新的root。

在Maze.class中,要先创建walls[],然后使这些wall的排序处于一个随机的状态。可以将前一半的wall设置成有序,后一半的wall设置成无序的负数,然后用题目提示的交换首尾的方法使整个wall[]变成random。最后通过cell的union把不同set结合在一起,将hWalls[]或vWalls[]的boolean值设置为false,remove the walls. 

The end.


以下为题目中需要fill out 的代码:

/**
     * Fill in the rest of this method.  You should go through all the walls of
     * the maze in random order, and remove any wall whose removal will not
     * create a cycle.  Use the implementation of disjoint sets provided in the
     * set package to avoid creating any cycles.
     *
     * Note the method randInt() further below, which generates a random
     * integer.  randInt() generates
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值