"Algorithm" fourth edition idea running environment building new template small book maker
At the beginning of the construction, I had no idea that there would be so many problems. I've seen most of the tutorials on the web, built on eclipse, and haven't used idea-building tutorials. I believe that many readers, like me, did not use command-line compilation to run Java code while learning Java, and use the Eclipse tool directly to develop it, so when you see the book
% java BinarySerach xxx.txt < xxx.txt
, I was a little overwhelmed. The IDE I'm using now is idea, so I want to set up an environment under the sense that I don't have much to say about it.
Overview
The construction of the environment is divided into the following steps:
- Building a Java operating environment
- Idea's installation and cracking
- Download and configuration of the "algorithm" Runtime library
- Creation of idea project and use of command line in idea
The first two steps are not written, online tutorials a lot.
download and configuration of the "algorithm" Runtime library
- First, we need to download the runtime library provided by the author: click I download,
Download the contents of the red box
We need to download two content, one is the library, the other is the test data. The library is Algs4.jar, and the data is algs4-data.zip.
- Set up the directory C:\Program files\algs4 in the C drive Algs4.jar into it as follows:
Storage location of Algs4.jar
PS: Here you can put in any place you want to put, I just used to put on the C-drive.
- In the CLASSPATH environment variable, add the value C:\Program files\algs4\algs4.jar (the path that just deposited the Algs4.jar) as follows:
Settings for Environment variables
Online said, to add a semicolon, specifically I did not go to the drill, so it.
In this way, the configuration of the library is completed. There is also a use of test data in the next section.
creation of idea projects and use of commands in idea
- Create a HelloWorld Project
Enter description here
Choose your JDK, I'm using 1.6.
- Add a jar package to a project
Project Structure
Add a Jar Package
- Unzip the test data into the SRC directory:
Unzip the test data into the SRC directory
- Write the test Code (code in section 1.3)
PackageTest; Public class fixedcapacitystackofstrings {Privatestring[] Stack;Private intN Fixedcapacitystackofstrings (intCAP) {stack =NewSTRING[CAP]; }Public String pop() {returnSTACK[--N]; }Public boolean isEmpty() {returnn==0; }Public int size() {returnN }Public void push(String s) {stack[n++] = s; }}
PackageTest;ImportEdu.princeton.cs.algs4.StdIn;ImportEdu.princeton.cs.algs4.StdOut; Public class fixedcapacitystackofstringtest {Public static void main(string[] args) {Fixedcapacitystackofstrings s =NewFixedcapacitystackofstrings ( -); while(! Stdin.isempty ()) {String item = stdin.readstring ();if(!item.equals ("-") {S.push (item); }Else if(!s.isempty ()) {Stdout.print (S.pop () +" "); }} stdout.println ("("+s.size () +"left"+")"); }}
Test results
Above, just fine.
Algorithm fourth version of IDEA running environment build