一 安装环境

直接下载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例子的更多相关文章

  1. 算法第四版 在Eclipse中调用Algs4库

    首先下载Eclipse,我选择的是Eclipse IDE for Java Developers64位版本,下载下来之后解压缩到喜欢的位置然后双击Eclipse.exe启动 然后开始新建项目,File ...

  2. 二项分布。计算binomial(100,50,0.25)将会产生的递归调用次数(算法第四版1.1.27)

    算法第四版35页问题1.1.27,估计用一下代码计算binomial(100,50,0.25)将会产生的递归调用次数: public static double binomial(int n,int ...

  3. 算法第四版jar包下载地址

    算法第四版jar包下载地址:https://algs4.cs.princeton.edu/code/

  4. 算法第四版-文字版-下载地址-Robert Sedgewick

    下载地址:https://download.csdn.net/download/moshenglv/10777447 算法第四版,文字版,可复制,方便copy代码 目录: 第1章 基 础 ...... ...

  5. 算法第四版学习笔记之优先队列--Priority Queues

    软件:DrJava 参考书:算法(第四版) 章节:2.4优先队列(以下截图是算法配套视频所讲内容截图) 1:API 与初级实现 2:堆得定义 3:堆排序 4:事件驱动的仿真 优先队列最重要的操作就是删 ...

  6. 算法第四版学习笔记之快速排序 QuickSort

    软件:DrJava 参考书:算法(第四版) 章节:2.3快速排序(以下截图是算法配套视频所讲内容截图) 1:快速排序 2:

  7. 配置《算法 第四版》的Eclipse开发环境

    1. 安装JAVA JAVA网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 配置环境变量(我把JAVA安装在 ...

  8. 用eclipse运行算法第四版的BinarySearch

    import java.util.Arrays; import edu.princeton.cs.algs4.In; import edu.princeton.cs.algs4.StdIn; impo ...

  9. 算法第四版 coursera公开课 普林斯顿算法 ⅠⅡ部分 Robert Sedgewick主讲《Algorithms》

    这是我在网上找到的资源,下载之后上传到我的百度网盘了. 包含两部分:1:算法视频的种子 2:字幕 下载之后,请用迅雷播放器打开,因为迅雷可以直接在线搜索字幕. 如果以下链接失效,请在下边留言,我再更新 ...

随机推荐

  1. EL函数以及自定义标签的应用

    一.EL函数(调用普通类的静态方法) 编写步骤(自定义EL函数的编写步骤即自定义标签的编写步骤): ①编写一个普通的java类,提供一个静态方法,功能自定,例如下: package cn.wzbril ...

  2. 《大道至简》第一章——编程的精义_读后感(Java伪代码形式)

    <大道至简>第一章——编程的精义_读后感(Java伪代码形式)1.愚公移山//愚公为团体的项目组织者.团体经理.编程人员.技术分析师等//子孙荷担者三人为三名技术人员//遗男为外协//目标 ...

  3. IOS 开发调用打电话,发短信

    1.调用 自带mail[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzl ...

  4. mount windows-linux文件共享

    . (2)在linux下访问windows共享: smbclient -L 192.168.2.12 -U admin   //查看共享了那些目录,由此知道主机名为XIAOXING-PC smbcli ...

  5. 编写一个简单的jdbc例子程序

    package it.cast.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Res ...

  6. Redmi Note3 hennessy 刷机过程记录

    本文只是凭记忆,记录大致的步骤,提供线索. 准备 刷机包和supersu刷机包,到xiaomi.eu上下载, 如果是稳定版可能有锁bootloader,需要到下载解锁软件.开发版无锁 刷入recove ...

  7. Hyper-V~双网卡设置

    Windows: Win10 有线网卡+无线网卡各一块 Hyper-V: 10.0.10240.16384 公司网络服务器180网段,公网192.168.0.*网段 家里网络:192.168.1.*网 ...

  8. 准备上线,切换到master分支,报错

    切换到master分支,准备上线,把上次上线sourceTree保存的修改拉出来: 运行,报错了: stackOverflow一搜说要删除旧的: 我show in finder 把他删了,然后双击安装 ...

  9. linux下安装svn server

    1. yum install subversion 2. mkdir -p /home/svn/svnfile 3. svnadmin create /home/svn/svnfile 4. 进入co ...

  10. js == 与 === 的区别,‘’与“”的区别

    js == 与 === 的区别 1.对于string,number等基础类型,==和===是有区别的 1)不同类型间比较,==之比较"转化成同一类型后的值"看"值&quo ...