Encaseデータ構造のArayClass

7778 ワード

1,概要
ArayClassはどのオブジェクトコンテナですか?クラスではなく、プログラミング言語のキーワードtypedef(別名)に似ています.
その本質は
typedef String[]StrigAray
ArayClassは必要に応じてSet Count()でメモリを割り当てることができます.
次の2つの方法で配列を作成します.
一つは、構造関数を使用することによって、もう一つは、array{asd}、“cds”、“vfd”、“fdg”などの声明を表示することである.
 
2,アラクラスのエニュメレート・タイプ
 
Name
Value
Description
SORT ENABLED
128
並べ替え(昇順)
SORTDESCENDING
256
降順に並べる
SORTCASE
512
条件付き並べ替え(大文字と小文字がある場合)
SORTNODUPE
1024
重量を除く
3,ArayClassにおける方法
Name
Return Type
Declaration
Description
ArayClass
void
ArayClass(uint Count=0,uint Size=0)
Aray Costructor Agments:count-the number of items to intialize-the number of items to alcate memory
Add
void
Add(void Value)
Adds_an item to this array,or else a Comple Eror will occurr.Agments:value-must be of the same type as the other oject s in this array does not have enough allocated space,the Add the the melocated
Count
uint
const Count()
Returns the number of items in this array--not the memory size of this array.
Delete
uint
Delete(uint index,uint Count=1)
Delete items from this array.Agments:index-unsigned integer zro-based index of item to delete count-unsigned integer number of items to delete after(and includeng)indeindex.If count is,zereb
DynamicType
SymboolClass
const DynamicType()
Returns the smbol object representing the dynamic type of this object.Symbol oject contain class names,method names and properties
Set Count
void
Set Count(uint Value)
Sets a new maximsize for the array Agments:Value-New size of the array
Type Cast
ArayClass
static Type Cast(Object Class Value)
Casts value to this type.Returns null if value is not of type
~アラークラス
void
~アラークラス()
Destruct-deletes the object from memory.This method cannot be caled directly.Ence will call it whenever there reのmore references to this oject
4,Aray条件方法
Name
Return Type
Declaration
Description
ソト
void
Sort(uint options=ArayClass:SORT ENABLED)
Sorts the array.'options'arrayClass::SortOptions:SORTENABLED,ArayClass::SortOptions:SORTDESCENDING,ArayClass::SortOptions,ArayClass:SorayClass:SortOptions
Find
要点
Find(void value、uint options=0、uint start=0、length=-1)
Returns the index of the first matching value、or-1 if not found.'value'is value to search for.'options'ars'arass::FindOptions:CASE(e.g.String):FindOptions:FindOptions:CASE.stars.stars'startiness's.stars's.stars.
5,サンプル
例1:行列を作成し、その内容を出力し、そのうちの3-7を削除し、再度配列の内容を印刷します.
class MainClass {

  typedef int[] IntArray;

  void Main() {
    //bool worked;
    int notWorks;
    IntArray arr(0, 15), //create an empty array with at most 15 items
             testArr(0, 5);
    testArr.Add(0); // adding the elements to the testArr array
    testArr.Add(1);
    testArr.Add(2);
    testArr.Add(8);
    testArr.Add(9);
    for (int i = 0; i < 10; i++) {
      arr.Add(i);
    }
    //print array contents
    int cnt = arr.Count(); //count() returns # of objects not MAX size
    for (int i = 0; i < cnt; i++) {
      Console.Write("\t\t" + arr[i]);
      if (arr[i] != i)
        notWorks++;
    }
    Console.WriteLine("");
    //delete items 3-7
    arr.Delete(3, 5);
    //print array objects
    cnt = arr.Count();
    for (int i = 0; i < cnt; i++) {
      Console.Write("\t\t" + arr[i]);
      if (testArr[i] != arr[i])
        notWorks++;
    }
    if (notWorks == 0)
      Console.WriteLine("
Worked"); else Console.WriteLine("
Does not Work"); } }
出力結果
  0  1  2  3  4  5  6  7  8  9  0  1  2  8  9ワード
例2:オブジェクト配列を作成します.
class AClass {

  String Name;
  AClass(const String &s = ""):
    Name = s
  {
  }
}

class MainClass {
  typedef AClass[] ClassArray;
  typedef int[] IntArray;
  void Main() {
    ClassArray arrClass {    }; //create an empty array
    IntArray testArr(0, 5);
    testArr.Add(0); // adding the elements to the testArr array
    testArr.Add(1);
    testArr.Add(2);
    testArr.Add(8);
    testArr.Add(9);
    int notWorks;
    for (int i = 0; i < 10; i++)
      arrClass.Add(new AClass(i));
    //print array contents
    int cnt = arrClass.Count(); //count() returns # of objects not MAX size
    for (int i = 0; i < cnt; i++) {
      Console.Write("\t\t" + arrClass[i].Name);
      if (arrClass[i].Name != i)
        notWorks++;
    }
    Console.WriteLine("");
    //delete items 3-7
    arrClass.Delete(3, 5);
    //print array objects
    cnt = arrClass.Count();
    for (int i = 0; i < cnt; i++) {
      Console.Write("\t\t" + arrClass[i].Name);
      if (arrClass[i].Name != testArr[i])
        notWorks++;
    }
    if (notWorks == 0)
      Console.WriteLine("
Worked"); else Console.WriteLine("
Does not Work"); } }
出力結果
  0  1  2  3  4  5  6  7  8  9  0  1  2  8  9ワード
パラダイム3:多次元配列
class MainClass {
  typedef int[]      IntArray;
  typedef IntArray[] Matrix;

  void Main() {
    IntArray testArr(0, 6),
             test2Arr(0, 6);
    testArr.Add(1); // adding the elements to the testArr array
    testArr.Add(0);
    testArr.Add(0);
    testArr.Add(0);
    testArr.Add(0);
    testArr.Add(1);
    int      topIndex = 0,
             secongIndex = 0,
             notWorks = 0;
    Matrix m(2);
    foreach (IntArray a in m)
      a = new IntArray(3);

    m[0][0] = 1; // only initialising m[0][0] and m[1][2] to "1". So the other elements should be "0"
    m[1][2] = 1;

    foreach (IntArray a in m) {
      secongIndex = 0;
      foreach (int i in a) {
        Console.WriteLine("\tm["+topIndex+"]["+secongIndex+"] = "+i);
        test2Arr.Add(i);
        secongIndex++;
      }
      topIndex++;
    }
    for(int index = 0; index < 6; index++) {
      if (testArr[index] != test2Arr[index])
        notWorks++;
    }
    if (notWorks == 0)
      Console.WriteLine("Worked");
    else
      Console.WriteLine("Does not Work");
  }
}
出力結果
 m[0][0]=1 m[0][1]=0 m[0][2]=0 m[1][0]=0 m[1][1]=0 m[1][2]=1ワード
例4:並べ替え方法
class MainClass {
  typedef String[] StringArray;
  void Show(const String &name,StringArray a) {
    Console.Write(name + ": ");
    foreach (String s in a)
      Console.Write(s);
    Console.WriteLine();
  }
  void Main() {
    SystemClass::ClearConsole(SystemClass::SHOWCONSOLE);
    StringArray a1 {"c","F","B","D","A","H","K","e","J","i","g"},b1();
    Show("Original",a1);

    // Add strings in a to b in sorted order
    b1.Sort(SORTENABLED);
    foreach (String s in a1)
      b1.Add(s);
    Show("Ascending",b1);

    // Resort array in descending order
    b1.Sort(SORTENABLED | SORTDESCENDING);
    Show("Descending",b1);

    // Resort array with case sensitive comparison
    b1.Sort(SORTENABLED | SORTCASE);
    Show("Case Sensitive",b1);

    // Add strings in a to b in sorted order,removing duplicate values
    StringArray a2 {"a","a","a","b","b","b","b","c","c","c","c"},b2();
    b2.Sort(SORTENABLED | SORTNODUPE);
    foreach (String s in a2)
      b2.Add(s);
    Show("De-Duped",b2);
  }
}
出力結果
Original:cFBDAHKeJig Acending:ABcDeFgHJK Descending:KJHgFeDcBA Case Sensitive:ABDFHJKcegi De-Dupt:abc