"Algorithm" fourth edition idea running environment construction

Source: Internet
Author: User
Tags stdin

"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
    1. 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.

    1. 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.

    1. 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
    1. Create a HelloWorld Project


Enter description here

Choose your JDK, I'm using 1.6.

    1. Add a jar package to a project


Project Structure


Add a Jar Package

    1. Unzip the test data into the SRC directory:


Unzip the test data into the SRC directory

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.