算法第四版 用eclipse实现书中UnionFind例子
一 安装环境
直接下载algs4.exe
下载完成后C:\Users\zle 下面会有algs4 文件夹

原文:
Our installer downloads, installs, and configures the Java programming environment you will be using, including Java SE 7, DrJava, the textbook libraries, and the Command Prompt.
- Log in to the user account in which you will be programming. Your account must have Administrator privileges and you must be connected to the Internet.
- Download algs4.exe and double-click it to perform the installation. If you receive a User Account Control alert before the installation, click Yes or Allow; if you receive a Program Compatibility Assistant alert after the installation, click This program installed correctly.
- If the installation succeeds, you will see the following:
- A Command Prompt windows containing approximately this execution log
- A Standard Drawing window containing a blue bullseye and textbook graphic.
Note that the installation can take several minutes or longer if you have a slow internet connection.
- Delete algs4.exe.
二 将这个文件夹复制到eclipse工作环境下

3 在eclipse中设置cmd环境

选择 External tools configrations

Name 名字随便取我的是UF1.5
Location 是cmd的目录
working director 默认的工作目录
三 编写程序并运行
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut; public class WeightedQuickUnionUF {
private int[] id; // id[i] = parent of i
private int[] sz; // sz[i] = number of objects in subtree rooted at i
private int count; // number of components // Create an empty union find data structure with N isolated sets.
public WeightedQuickUnionUF(int N) {
count = N;
id = new int[N];
sz = new int[N];
for (int i = 0; i < N; i++) {
id[i] = i;
sz[i] = 1;
}
} // Return the number of disjoint sets.
public int count() {
return count;
} // Return component identifier for component containing p
public int find(int p) {
while (p != id[p])
p = id[p];
return p;
} // Are objects p and q in the same set?
public boolean connected(int p, int q) {
return find(p) == find(q);
} // Replace sets containing p and q with their union.
public void union(int p, int q) {
int i = find(p);
int j = find(q);
if (i == j) return; // make smaller root point to larger one
if (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; }
else { id[j] = i; sz[i] += sz[j]; }
count--;
} public static void main(String[] args) {
int N = StdIn.readInt();
WeightedQuickUnionUF uf = new WeightedQuickUnionUF(N); // read in a sequence of pairs of integers (each in the range 0 to N-1),
// calling find() for each pair: If the members of the pair are not already
// call union() and print the pair.
while (!StdIn.isEmpty()) {
int p = StdIn.readInt();
int q = StdIn.readInt();
if (uf.connected(p, q)) continue;
uf.union(p, q);
StdOut.println(p + " " + q);
}
StdOut.println("# components: " + uf.count());
} }
点击刚刚创建的UF1.5

在console可以看到cmd

进入bin 目录下 因为.class文件在bin目录下

在命令框内输入

折磨了好久终于搞好啦!
参考:http://algs4.cs.princeton.edu/windows/
算法第四版 用eclipse实现书中UnionFind例子的更多相关文章
- 算法第四版 在Eclipse中调用Algs4库
首先下载Eclipse,我选择的是Eclipse IDE for Java Developers64位版本,下载下来之后解压缩到喜欢的位置然后双击Eclipse.exe启动 然后开始新建项目,File ...
- 二项分布。计算binomial(100,50,0.25)将会产生的递归调用次数(算法第四版1.1.27)
算法第四版35页问题1.1.27,估计用一下代码计算binomial(100,50,0.25)将会产生的递归调用次数: public static double binomial(int n,int ...
- 算法第四版jar包下载地址
算法第四版jar包下载地址:https://algs4.cs.princeton.edu/code/
- 算法第四版-文字版-下载地址-Robert Sedgewick
下载地址:https://download.csdn.net/download/moshenglv/10777447 算法第四版,文字版,可复制,方便copy代码 目录: 第1章 基 础 ...... ...
- 算法第四版学习笔记之优先队列--Priority Queues
软件:DrJava 参考书:算法(第四版) 章节:2.4优先队列(以下截图是算法配套视频所讲内容截图) 1:API 与初级实现 2:堆得定义 3:堆排序 4:事件驱动的仿真 优先队列最重要的操作就是删 ...
- 算法第四版学习笔记之快速排序 QuickSort
软件:DrJava 参考书:算法(第四版) 章节:2.3快速排序(以下截图是算法配套视频所讲内容截图) 1:快速排序 2:
- 配置《算法 第四版》的Eclipse开发环境
1. 安装JAVA JAVA网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 配置环境变量(我把JAVA安装在 ...
- 用eclipse运行算法第四版的BinarySearch
import java.util.Arrays; import edu.princeton.cs.algs4.In; import edu.princeton.cs.algs4.StdIn; impo ...
- 算法第四版 coursera公开课 普林斯顿算法 ⅠⅡ部分 Robert Sedgewick主讲《Algorithms》
这是我在网上找到的资源,下载之后上传到我的百度网盘了. 包含两部分:1:算法视频的种子 2:字幕 下载之后,请用迅雷播放器打开,因为迅雷可以直接在线搜索字幕. 如果以下链接失效,请在下边留言,我再更新 ...
随机推荐
- Shader实例:边缘发光和描边
效果图: 1.边缘发光 思路:用视方向和法线方向点乘,模型越边缘的地方,它的法线和视方向越接近90度.点乘越接近0 那么用 1-减去上面点乘的结果,来作为颜色分量,来反映边缘颜色强弱. Shader ...
- 20145205 《Java程序设计》第9周学习总结
教材学习内容总结 第十六章 JDBC简介 撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找 JDBC目的:让Java程序设计人员在撰写数据库操作程序时可以有个统一的接口,无须依赖特 ...
- 第一章-第三题(目前流行的源程序版本管理软件和项目管理软件优缺点)--By梁旭晖
引用自:http://www.cnblogs.com/WJ1234/p/5285595.htmlhttp://blog.163.com/yuyang_tech/blog/static/21605008 ...
- 浮点数 (IEEE-754)
浮点数又称"实数",一个浮点数包含三个部分 符号位(S) 阶码 有效数字 S:阶码:有效数字 浮点数是由科学二级制来表示的. 三种类型的浮点数: 短浮点数(32bit): S(b ...
- ssh项目java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade错误
错误: 导入别人的ssh项目后出现java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade错误, 错 ...
- json字符串转泛型集合对象
Dictionary<string, object> jd = js.Deserialize<Dictionary<string, object>>(item); ...
- python学习道路(day7note)(subprocess模块,面向对象)
1.subprocess模块 因为方法较多我就写在code里面了,后面有注释 #!/usr/bin/env python #_*_coding:utf-8_*_ #linux 上调用python脚 ...
- JavaScript Array 常用函数整理
按字母顺序整理 索引 Array.prototype.concat() Array.prototype.filter() Array.prototype.indexOf() Array.prototy ...
- PHP 获取两个日期之间的日期数组/月份数组
function getEmptyArr($s_time,$e_time,$type){ $tmp = array(); if($type=='day'){ $s_time = strtotime($ ...
- 极光推送Jpush(v3)服务端PHP版本的api脚本类
原文地址:http://www.dodobook.net/php/780 关于极光推送的上一篇文章已经说明了,此处就不多说了.使用v3版本的原因是v2使用到2014年年底就停止了.点击查看上一篇的地址 ...