1 / 11

set u = s.union(t);

class settest { public static void main(String args[]) {. s={Adachi,Fujigaki,Hiraki,KYamaguchi,Kato,Kawai,Masuhara,Nagano,Nakamura,Niwa,Okatsu,Suzuki,Tamai,Ueda,YYamaguchi}

alanna
Download Presentation

set u = s.union(t);

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. class settest { public static void main(String args[]) { s={Adachi,Fujigaki,Hiraki,KYamaguchi,Kato,Kawai,Masuhara,Nagano,Nakamura,Niwa,Okatsu,Suzuki,Tamai,Ueda,YYamaguchi} t={Fujigaki,Hiraki,KYamaguchi,Kanazawa,Kawachiya,Makino,Masuhara,Nagano,Nakamura,Niwa,Ogawa,Oiwa,Okatsu,Sai,TTanaka,Tamai,Tamura,Tsutsumi,Ueda,YYamaguchi,Yoshioka} set u = s.union(t);

  2. ti to this {Adachi,Fujigaki,Hiraki,KYamaguchi,Kato, Kawai,Masuhara,Nagano,Nakamura,Niwa, Okatsu,Suzuki,Tamai,Ueda,YYamaguchi} ao ai another {Fujigaki,Hiraki,KYamaguchi,Kanazawa, Kawachiya,Makino,Masuhara,Nagano,Nakamura, Niwa,Ogawa,Oiwa,Okatsu,Sai,TTanaka,Tamai, Tamura,Tsutsumi,Ueda,YYamaguchi,Yoshioka} public set union(set another) { set result = new set(); Comparable to = null, ao = null; Iterator ti = this.body.iterator(); Iterator ai = another.body.iterator();

  3. to ti this {Adachi,Fujigaki,Hiraki,KYamaguchi,Kato, Kawai,Masuhara,Nagano,Nakamura,Niwa, Okatsu,Suzuki,Tamai,Ueda,YYamaguchi} ao ai another {Fujigaki,Hiraki,KYamaguchi,Kanazawa, Kawachiya,Makino,Masuhara,Nagano,Nakamura, Niwa,Ogawa,Oiwa,Okatsu,Sai,TTanaka,Tamai, Tamura,Tsutsumi,Ueda,YYamaguchi,Yoshioka} while(true) { if (to == null && ti.hasNext()) to = (Comparable)ti.next(); if (ao == null && ai.hasNext()) ao = (Comparable)ai.next();

  4. while(true) { if (to == null && ti.hasNext()) to = (Comparable)ti.next(); if (ao == null && ai.hasNext()) ao = (Comparable)ai.next(); if (to == null) if (ao == null) break; else { result.body.add(ao); ao = null; } else if (ao == null) { result.body.add(to); to = null; } else { int i = to.compareTo(ao); if (i > 0) { result.body.add(ao); ao = null; } else if (i < 0) { result.body.add(to); to = null; } else { result.body.add(ao); ao = to = null; } } } to ti {Adachi,Fujigaki,Hiraki,KYamaguchi,Kato, Kawai,Masuhara,Nagano,Nakamura,Niwa, Okatsu,Suzuki,Tamai,Ueda,YYamaguchi} ao ai {Fujigaki,Hiraki,KYamaguchi,Kanazawa, Kawachiya,Makino,Masuhara,Nagano,Nakamura, Niwa,Ogawa,Oiwa,Okatsu,Sai,TTanaka,Tamai, Tamura,Tsutsumi,Ueda,YYamaguchi,Yoshioka} result {Adachi}

  5. while(true) { if (to == null && ti.hasNext()) to = (Comparable)ti.next(); if (ao == null && ai.hasNext()) ao = (Comparable)ai.next(); if (to == null) if (ao == null) break; else { result.body.add(ao); ao = null; } else if (ao == null) { result.body.add(to); to = null; } else { int i = to.compareTo(ao); if (i > 0) { result.body.add(ao); ao = null; } else if (i < 0) { result.body.add(to); to = null; } else { result.body.add(ao); ao = to = null; } } } ti to {Adachi,Fujigaki,Hiraki,KYamaguchi,Kato, Kawai,Masuhara,Nagano,Nakamura,Niwa, Okatsu,Suzuki,Tamai,Ueda,YYamaguchi} ao ai {Fujigaki,Hiraki,KYamaguchi,Kanazawa, Kawachiya,Makino,Masuhara,Nagano,Nakamura, Niwa,Ogawa,Oiwa,Okatsu,Sai,TTanaka,Tamai, Tamura,Tsutsumi,Ueda,YYamaguchi,Yoshioka} result {Adachi}

  6. while(true) { if (to == null && ti.hasNext()) to = (Comparable)ti.next(); if (ao == null && ai.hasNext()) ao = (Comparable)ai.next(); if (to == null) if (ao == null) break; else { result.body.add(ao); ao = null; } else if (ao == null) { result.body.add(to); to = null; } else { int i = to.compareTo(ao); if (i > 0) { result.body.add(ao); ao = null; } else if (i < 0) { result.body.add(to); to = null; } else { result.body.add(ao); ao = to = null; } } } ti to {Adachi,Fujigaki,Hiraki,KYamaguchi,Kato, Kawai,Masuhara,Nagano,Nakamura,Niwa, Okatsu,Suzuki,Tamai,Ueda,YYamaguchi} ao ai {Fujigaki,Hiraki,KYamaguchi,Kanazawa, Kawachiya,Makino,Masuhara,Nagano,Nakamura, Niwa,Ogawa,Oiwa,Okatsu,Sai,TTanaka,Tamai, Tamura,Tsutsumi,Ueda,YYamaguchi,Yoshioka} result {Adachi,Fujigaki}

  7. while(true) { if (to == null && ti.hasNext()) to = (Comparable)ti.next(); if (ao == null && ai.hasNext()) ao = (Comparable)ai.next(); if (to == null) if (ao == null) break; else { result.body.add(ao); ao = null; } else if (ao == null) { result.body.add(to); to = null; } else { int i = to.compareTo(ao); if (i > 0) { result.body.add(ao); ao = null; } else if (i < 0) { result.body.add(to); to = null; } else { result.body.add(ao); ao = to = null; } } } ti to {Adachi,Fujigaki,Hiraki,KYamaguchi,Kato, Kawai,Masuhara,Nagano,Nakamura,Niwa, Okatsu,Suzuki,Tamai,Ueda,YYamaguchi} ao ai {Fujigaki,Hiraki,KYamaguchi,Kanazawa, Kawachiya,Makino,Masuhara,Nagano,Nakamura, Niwa,Ogawa,Oiwa,Okatsu,Sai,TTanaka,Tamai, Tamura,Tsutsumi,Ueda,YYamaguchi,Yoshioka} result {Adachi,Fujigaki}

  8. {Adachi,Fujigaki,Hiraki,KYamaguchi,Kato,... それぞれの先頭を比較して小さい方を結果に追加する。 {Fujigaki,Hiraki,KYamaguchi,Kanazawa,... {}

  9. {Fujigaki,Hiraki,KYamaguchi,Kato,... それぞれの先頭を比較して小さい方を結果に追加する。 {Fujigaki,Hiraki,KYamaguchi,Kanazawa,... {Adachi}

  10. {Hiraki,KYamaguchi,Kato,... それぞれの先頭が同じ値のときは両方除く {Hiraki,KYamaguchi,Kanazawa,... {Adachi, Fujigaki}

  11. {} {Yoshioka} 一方が空になったら残っている方をコピーする。 {Adachi, Fujigaki,...,YYamaguchi}

More Related