9 11 8 21 22 7 6 5 4 3 2 1 0 |
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
//★ ArrayList の連鎖 前田 稔 ★
using System;
using System.Collections; //ArrayList を使うとき
class Cell
{ public ArrayList pt = new ArrayList();
public int v;
}
class Prog
{
public static void Main()
{ Cell top = null;
Cell wk,wp;
int i;
for(i=0; i<10; i++)
{ wk = new Cell();
wk.v = i;
wk.pt.Add(top);
top = wk;
}
for(wk=top; wk!=null; wk=(Cell)wk.pt[0])
Console.WriteLine(wk.v);
Console.ReadLine();
}
}
|
class Cell
{ public ArrayList pt = new ArrayList();
public int v;
}
|
public static void Main()
{ Cell top = null;
Cell wk;
int i;
for(i=0; i<10; i++)
{ wk = new Cell();
wk.v = i;
wk.pt.Add(top);
top = wk;
}
|
for(wk=top; wk!=null; wk=(Cell)wk.pt[0])
Console.WriteLine(wk.v);
Console.ReadLine();
|
![]()
class Cell
{ public ArrayList pt = new ArrayList();
public int v;
}
|
wk = new Cell();
wk.v = 11;
top.pt.Add(wk);
|
wk = new Cell();
wk.v = 21;
wp = (Cell)top.pt[0];
wp.pt.Add(wk);
wk = new Cell();
wk.v = 22;
wp.pt.Add(wk);
|
for (wk=top; wk!=null; wk=(Cell)wk.pt[0])
{ Console.WriteLine(wk.v);
for(i=1; i<wk.pt.Count; i++)
{ wp = (Cell)wk.pt[i];
Console.WriteLine(wp.v);
}
}
Console.ReadLine();
|
![]()