welcome: please sign in
location: "リスト処理の演習"の差分
16と17のリビジョン間の差分
2010-11-17 00:31:07時点のリビジョン16
サイズ: 1237
編集者: masahiko
コメント:
2010-11-17 04:26:08時点のリビジョン17
サイズ: 1237
編集者: masahiko
コメント:
削除された箇所はこのように表示されます。 追加された箇所はこのように表示されます。
行 58: 行 58:
 . {{attachment:chain11.png}}  . {{attachment:chain12.png}}

課題07

Chainクラスを作成し、次のいずれかを行うmainメソッドを記述しなさい。

  •    1 public class Chain
       2 {
       3         Chain next;
       4 
       5         void show()
       6         {
       7                 System.out.println(this);
       8         }
       9 
      10         void showAll()
      11         {
      12                 Chain c;
      13 
      14                 c = this;
      15                 System.out.println("(");
      16                 while(c != null)
      17                 {
      18                         c.show();
      19                         c = c.next;
      20                 }
      21                 System.out.println(")");
      22         }
      23         
      24         public static void main(String[] args)
      25         {
      26                 Chain a, b, c;
      27                 ...
      28         }
      29 }
    


1. (初級)

mainメソッド内の変数a,b,cが図のようなオブジェクトを参照しているようにした後

  • a.showAll();
    b.showAll();
    c.showAll();

を行って動作を確かめなさい。

  • chain11.png

ヒント

  • インスタンスは必要な個数(7つ) new Chain() で作成します。


2. (中級)

1と同じことを、 next.next のような記述をしないで行いなさい。

ヒント

  • 作業用の変数が1つ必要です。


3. (上級)

1と同じことを、インスタンスを次の順で作成して行いなさい。

  • chain12.png

ヒント

  • 作業用の変数はa,b,cの他に1つとする。

リスト処理の演習 (最終更新日時 2012-03-27 05:02:27 更新者 masahiko)