110 likes | 247 Views
class settest { public static void main(String args[]) {. s={Adachi,Fujigaki,Hiraki,KYamaguchi,Kato,Kawai,Masuhara,Nagano,Nakamura,Niwa,Okatsu,Suzuki,Tamai,Ueda,YYamaguchi}
E N D
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);
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();
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();
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}
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}
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}
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}
{Adachi,Fujigaki,Hiraki,KYamaguchi,Kato,... それぞれの先頭を比較して小さい方を結果に追加する。 {Fujigaki,Hiraki,KYamaguchi,Kanazawa,... {}
{Fujigaki,Hiraki,KYamaguchi,Kato,... それぞれの先頭を比較して小さい方を結果に追加する。 {Fujigaki,Hiraki,KYamaguchi,Kanazawa,... {Adachi}
{Hiraki,KYamaguchi,Kato,... それぞれの先頭が同じ値のときは両方除く {Hiraki,KYamaguchi,Kanazawa,... {Adachi, Fujigaki}
{} {Yoshioka} 一方が空になったら残っている方をコピーする。 {Adachi, Fujigaki,...,YYamaguchi}