Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
ArrayList の連鎖
ArrayList 自体が List 構造をしているのですが、これを連鎖して二重の連鎖構造を構築します。
最初のステップとして、ArrayList を単純に連鎖してみましょう。
ArrayList の基礎は ArrayList の基礎 を参照して下さい。
ArrayList に Class の登録は Object Class を登録 を参照して下さい。
//★ 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 が連鎖する構造体(Class)で、pt で Cell を連鎖します。
pt 自体が ArrayList で List 構造を持っています。
メンバーとして int 型の値を格納する v を定義しています。
class Cell
{ public ArrayList pt = new ArrayList();
public int v;
}
top が連鎖する構造体のトップポインターです。
wk, wp は作業用で、ArrayList の連鎖に使用します。
10個の Cell を連載して、0~9の値を格納します。
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;
}