class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

Similar documents
class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

DVIOUT-interface-he

1.1 (1) (2) (3) (4) 2

DVIOUT-exer

新・明解Java入門

ALG2012-A.ppt

Java学習教材

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

untitled

K227 Java 2

extends (*) (*) extend extends 2

アルゴリズムとデータ構造1

ALG ppt

ALG2012-C.ppt

untitled

Java演習(4) -- 変数と型 --

ALG ppt

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

解きながら学ぶJava入門編

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C

JAVA とテンプレート

I java A

明解Javaによるアルゴリズムとデータ構造

Java (5) 1 Lesson 3: x 2 +4x +5 f(x) =x 2 +4x +5 x f(10) x Java , 3.0,..., 10.0, 1.0, 2.0,... flow rate (m**3/s) "flow

r1.dvi

アルゴリズムとデータ構造1

5 p Point int Java p Point Point p; p = new Point(); Point instance, p Point int 2 Point Point p = new Point(); p.x = 1; p.y = 2;

Java (7) Lesson = (1) 1 m 3 /s m 2 5 m 2 4 m 2 1 m 3 m 1 m 0.5 m 3 /ms 0.3 m 3 /ms 0.6 m 3 /ms 1 1 3

text_08.dvi

: : : TSTank 2

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

8 if switch for while do while 2

JavaプログラミングⅠ

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

Thread

Java プログラミング Ⅰ 3 回目変 数 今日の講義講義で学ぶ内容 変数とは 変数の使い方 キーボード入力の仕方 変 数 変 数 一時的に値を記憶させておく機能 変数は 型 ( データ型 ) と識別子をもちます 2 型 ( データ型 ) 変数に記憶する値の種類変数の型は 記憶できる値の種類と範囲

r02.dvi

ohp02.dvi

10K pdf

問題1 以下に示すプログラムは、次の処理をするプログラムである

1. はじめに 二分木ヒープ 様々なアルゴリズムにおいて ある要素の集合またはリストから 最小 な要素を取り 出す必要がある そのような場合に使われる標準的データ構造が二分木ヒープ (binary heap) である あるオブジェクトO を考える そのオブジェクトは ラベル O. label と値

226

目的 泡立ち法を例に Comparableインターフェイスの実装 抽象クラスの利用 型パラメタの利用 比較 入替 の回数を計測

2. データ構造ヒープに保存するデータは 番号付けられて保存される 従って リスト L として保存することとする 3. アルゴリズム 3.1. 要素の追加新しい要素の追加は リストの終端に置くことで開始する つまり 最下層の一番右 または新たに最下層を生成してその一番左となる この後 この要素を正し

アルゴリズムとデータ構造1

** 平成 16 年度 FE 午後問題 Java** 示現塾プロジェクトマネージャ テクニカルエンジニア ( ネットワーク ) など各種セミナーを開催中!! 開催日 受講料 カリキュラム等 詳しくは 今すぐアクセス!! 平成 16

untitled

二分木ヒープとは 集合 リストから 最小な 要素を取り出す 二分木ヒープは そのための標準的データ構造 二分木ヒープを保存するデータ構造 二分木ヒープの操作のメソッド 対象となるデータクラス 識別のためのlabelフィールド 値を保持するvalueフィールド

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。

Microsoft Word - NonGenTree.doc

問題1 以下に示すプログラムは、次の処理をするプログラムである

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A

ALG ppt

JavaプログラミングⅠ

デジタル表現論・第4回

新・明解Javaで学ぶアルゴリズムとデータ構造

Microsoft PowerPoint ppt

55 7 Java C Java TCP/IP TCP/IP TCP TCP_RO.java import java.net.*; import java.io.*; public class TCP_RO { public static void main(string[] a

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

Java プログラミング Ⅰ 3 回目変数 変数 変 数 一時的に値を記憶させておく機能型 ( データ型 ) と識別子をもつ 2 型 ( データ型 ) 変数の種類型に応じて記憶できる値の種類や範囲が決まる 型 値の種類 値の範囲 boolean 真偽値 true / false char 2バイト文

2

ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする ) ためには 同期処理を用いるこ とが必要になる 同期処理は 予約語 synchronized で行うことができる ここでは sy

Java updated

tkk0408nari

Exam : 1z0-809 日本語 (JPN) Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO 1 / 8 Get Latest & Valid 1z0-809-JPN Exam's Question and Answe

オブジェクト脳のつくり方

Java Java Java Java Java 4 p * *** ***** *** * Unix p a,b,c,d 100,200,250,500 a*b = a*b+c = a*b+c*d = (a+b)*(c+d) = 225

r3.dvi

Microsoft Word - keisankigairon.ch doc

Javaセキュアコーディングセミナー2013東京第1回 演習の解説

Microsoft Word - NonGenList.doc

2 static final int DO NOTHING ON CLOSE static final int HIDE ON CLOSE static final int DISPOSE ON CLOSE static final int EXIT ON CLOSE void setvisible

PowerPoint Presentation

I. (i) Java? (A). 2Apples (B). Vitamin-C (C). Peach21 (D). Pine_Apple (ii) Java? (A). Java (B). Java (C). Java (D). JavaScript Java JavaScript Java (i

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 今日の講義講義で学ぶ内容 switch 文 論理演算子 条件演算子 条件判断文 3 switch 文 switch 文 式が case のラベルと一致する場所から直後の break; まで処理しますどれにも一致致しない場合 def

Java演習(2) -- 簡単なプログラム --

ALG2012-F.ppt

NPCA部誌2018

Java講座

明解Javaによるアルゴリズムとデータ構造

(Java/FX ) Java CD Java version Java VC++ Python Ruby Java Java Eclipse Java Java 3 Java for Everyone 2 10 Java Midi Java JavaFX Shape Canvas C

シミュレーションの簡単な例 GUI 無しのシミュレーションを作る GUI を作る パラメタを設定するデモンストレーションをする 2 オブジェクト指向プログラミング特論

Q&A集

untitled

2

JavaプログラミングⅠ

Quick Sort 計算機アルゴリズム特論 :2017 年度 只木進一

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。

Java 基礎問題ドリル ~ メソッドを理解する ~ 次のプログラムコードに 各設問の条件にあうメソッドを追加しなさい その後 そのメソッドが正しく動作することを検証するためのプログラムコードを main メソッドの中に追加しなさい public class Practice { // ここに各設問

presen.gby


IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

解答上の注意 1 解答は 解答 紙の問題番号に対応した解答欄にマークしなさい 2 選択肢は 問ごとに 意されています 問 1の選択肢は 問 2で使 しません 3 選択肢は量が多いため 探しやすさの観点よりグループ分けされています グループ分けに合わせて解答欄が区切られていますが 横 1 列で問題 1

2

I HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 条件判断文 3 switch 文 switch 文式が case の値と一致した場合 そこから直後の break; までを処理し どれにも一致しない場合 default; から直後の break; までを処理する 但し 式や値 1

新・明解Javaで学ぶアルゴリズムとデータ構造

Javaセキュアコーディングセミナー東京 第2回 数値データの取扱いと入力値の検証 演習解説

untitled

Transcription:

Part2-1-3 Java (*) (*).class Java public static final 1

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value = value; IntCell(int value, IntCell cell) { this.value = value; next = cell; void showvalue() {System.out.print(value+" "); class IntList { private int size = 0; private IntCell firstcell = null; void tail() {// firstcell = firstcell.next(); size--; /* IntList IntCell IntCell so, polymorphism */ 2

1. 2. 3. 1. 2. 3. 3

Therefore, java.util 4

Heap: O(log n) 5

= (*) interface ObjectWithLessThan { boolean lessthan(objectwithlessthan y); void show(); // lessthan // lessthan // public int x ObjectWithLessThan x (x < y) x.lessthan(y) boolean lessthan(objectwithlessthan) (*) Java 6

class ClassName implements Interface1,Interface2,... implements public class Student implements ObjectWithLessThan{ private String name; private int score, code; public boolean lessthan(objectwithlessthan y) {// Student yrec = (Student)y; // /* y objectwithlessthan y Student y.name() yrec.name() Student */ return name.compareto(yrec.name) < 0; // return code < yrec.code; // // return score > yrec.score; // score public void show() { System.out.print(" "+name+","+score+" "); 7

class ζ {... σ method (τ 1 x 1,..., τ n x n ) {...... : ζ,, σ j,... : f : ζ, τ 1,..., τ n σ (ζ : self, this ) σ method (τ 1,..., τ n ) Java τ method (τ 1,..., τ n ) 1. (overload) 2., override 8

Interface z; z = (C)x; x C ow. : double z = 1.0; int x = (int)z; 9

class Heap { private ObjectWithLessThan[] heap; ObjectWithLessThan get(int index) {return heap[index]; private int size = 0; public int size() {return size; void reset() {size=0; private int capacity; Heap(int capacity) {// heap = new ObjectWithLessThan[capacity]; size = 0; this.capacity=capacity; private static int CAPACITY = 10000;// Heap() {// capacity = CAPACITY; heap = new ObjectWithLessThan[capacity]; size = 0; private void swap(int pt1, int pt2) { ObjectWithLessThan tmp; tmp=heap[pt1]; heap[pt1]=heap[pt2]; heap[pt2]=tmp; private boolean nonroot(int pt) {return pt > 0; // private int parent(int pt) {return (pt-1)/2; private int succ(int pt) { return 2*pt+1; private void insert(objectwithlessthan element){ if (++size > capacity) { System.out.println("*** "); System.exit(1); int pt, parent; heap[(pt=size-1)]=element; while(nonroot(pt) && heap[pt].lessthan(heap[(parent=parent(pt))])) { swap(pt,parent); pt = parent; ; void formheap(objectwithlessthan[] elements) { for (int i=0;i<elements.length;i++) insert(elements[i]); void showintheorder() { ObjectWithLessThan element; while ( (element=deletemin())!= null) element.show(); System.out.println(); 10

private ObjectWithLessThan deletemin(){ if (size==0) return null; ObjectWithLessThan min = heap[0]; heap[0] = heap[--size]; int pt = 0, branch; while((branch=succ(pt)) < size) { if (branch+1 < size && heap[branch+1].lessthan(heap[branch])) branch = branch+1; //take min among left and right childs if (!heap[branch].lessthan(heap[pt])) break; swap(branch,pt); pt = branch; ; return min; interface Show {// void show(); interface ObjectWithLessThan extends Show { boolean lessthan(objectwithlessthan y); class Teacher implements ObjectWithLessThan{ private int salary; private String name, division; Teacher(String name, String div, int salary) { this.salary=salary; this.name=name; division=div; public void show() { System.out.print("<"+name+","+division+","+salary+">, "); public boolean lessthan(objectwithlessthan y) { return salary < ((Teacher)y).salary; // class Student implements ObjectWithLessThan{ private String name; private int score; Student(String name, int score) {this.name=name; this.score=score; // public boolean lessthan(objectwithlessthan y) { return name.compareto(((student)y).name) < 0;//name public void show() {System.out.print("<"+name+","+score+">, "); 11

class MyInt implements ObjectWithLessThan{ private int value; MyInt(int i) {value = i; public boolean lessthan(objectwithlessthan y) { return value > ((MyInt)y).value; // public void show() {System.out.print("<"+value+">, "); class test { public static void main(string args[]){ Student[] ss = { new Student("mh",10), new Student("keiko",50), new Student("kenichi",100), new Student("taro",70) ; Teacher[] ts = {new Teacher("mh", "cs",400), new Teacher("sarah","physics",1000); MyInt[] is = {new MyInt(100), new MyInt(300), new MyInt(200); ObjectWithLessThan[][] testdata = {ss, ts, is;// Heap heap = new Heap(); for (int i=0;i<testdata.length;i++) { // heap.reset(); // heap heap.formheap(testdata[i]); System.out.print("+++ "+i+"-th sorted data: "); heap.showintheorder(); // heap ; ObjectWithLessThan[] objs = {new Student("satoshi",70), new MyInt(60); for (int i=0;i<objs.length;i++) objs[i].show(); System.out.println(); heap.formheap(objs);// c:\users\makoto\home\lecture\pl\resume>javac heap.java c:\users\makoto\home\lecture\pl\resume>java test +++ 0-th sorted data: <keiko,50>, <kenichi,100>, <mh,10>, <taro,70>, +++ 1-th sorted data: <mh,cs,400>, <sarah,physics,1000>, +++ 2-th sorted data: 300, 200, 100, <satoshi,70>, <60>, // Exception in thread "main" java.lang.classcastexception: Student cannot be cast to MyInt // lessthan //instanceof // // instancof 12

C1 {m11, m12 os1 {m21, m22 os2 13

Web Jave C ++ : Java 14

ConvexPolygon double boudarylength() (public) ObjectWithLessThan read() { if (size > 0) return deletemin(); else return null; Heap... class Point implements ObjectWithLessThan { private static final double PRECISION = 1.0e-7; // PRECISION private double x, y; double distance(point p) {//pow(x,y)=x^y ( ), sqrt return Math.sqrt(Math.pow(y-p.y,2)+Math.pow(x-p.x,2)); private static Point standardpoint; static void setstandardpoint(point p) { standardpoint=p; boolean eqx(point p) {// X return Math.abs(x - p.x) < PRECISION; public boolean lessthan(objectwithlessthan ap) { Point p = (Point)ap; if (eqx(standardpoint)) if (standardpoint.eqx(p)) return y + PRECISION < p.y; else return false; if (standardpoint.eqx(p)) return true; return slope(standardpoint) > p.slope(standardpoint) + PRECISION ; boolean pointeq(point p) {// return Math.abs(x-p.x) < PRECISION && Math.abs(y-p.y) < PRECISION ; public void show() {System.out.println("x="+x+", y="+y); 15

private double slope(point p) { return (y-p.y)/(x-p.x); /* (y-p.y)/(x-p.x) NaN, infinity slope Point private (Point ) lessthan lessthan. */ boolean morelefthigher(point p) { if ( x + PRECISION < p.x (eqx(p) && p.y + PRECISION < y) ) return true; else return false; class ConvexPolygon { private int nofpoints; // private Point[] points; // private Point standardpoint; private void setstandardpoint() { standardpoint = points[0]; for (int i=1;i<nofpoints;i++) if (points[i].morelefthigher(standardpoint)) standardpoint = points[i]; Point.setStandardPoint(standardPoint); private double boundarylength() { Heap heap = new Heap(nofPoints-1); //standardpoint for (int i=0;i<nofpoints;i++) if (!points[i].pointeq(standardpoint)) heap.insert(points[i]); double boundarylength = 0.0; Point presentpoint = standardpoint, nextpoint; while ((nextpoint = (Point)heap.read())!=null) { boundarylength += presentpoint.distance(nextpoint); presentpoint = nextpoint; ; return boundarylength + presentpoint.distance(standardpoint); public static void main(string args[]) { ConvexPolygon cp = new ConvexPolygon(); cp.readdatafromfile(args[0]); // // readdatafromfile points nofpoints cp.setstandardpoint(); System.out.println(" "+cp.boundarylength()); 16

1. lessthan 2.... Graham Jarvis Quickhull 17