在C#中编写数据结构Stack时,只能用数组,需要指定数组大小,但有时不知道要多少大小,在C++中可以用指针解决,C#中有没有类似C++中指针的东西,
还有javascript中的Array如何实现 Stack的Push和Pop,
请大家帮帮忙,给个例子!!给个例子

解决方案 »

  1.   

    string s="Code Project is cool"; 
       Console.Write("the original string : "); 
       Console.WriteLine("{0}\r\n",s); 
       
       char[] b = new char[100]; 
       s.CopyTo(0,b,0,20); 
       
       Console.Write("the encoded string : "); 
       unsafe fixed(char *p=b)NEncodeDecode(p); 
       for(int t=0;t<20;t++) 
       Console.Write(b[t]); 
       Console.WriteLine("\r\n"); 
       
       Console.Write("the decoded string : "); 
       unsafe fixed(char *p=b)NEncodeDecode(p); 
       for(int t=0;t<20;t++) 
       Console.Write(b[t]); 
       Console.WriteLine(); 
       
      } 
      unsafe public static void NEncodeDecode(char *s) 
      { 
       int w; 
       for(int y=0;y<20;y++) 
       { 
       w=(int)*(s+y); 
       w=w^5; 
       *(s+y)=(char)w; 
       } 
      } 
      

  2.   

    http://msdn2.microsoft.com/zh-cn/library/system.collections.arraylist(VS.80).aspx
      

  3.   

    // JS中的array本身就有pop和push方法pop 方法
    移除数组中的最后一个元素并返回该元素。arrayObj.pop( )必选的 arrayObj 引用是一个 Array 对象。说明
    如果该数组为空,那么将返回 undefined。
    push 方法
    将新元素添加到一个数组中,并返回数组的新长度值。arrayObj.push([item1 [item2 [. . . [itemN ]]]])参数
    arrayObj必选项。一个 Array 对象。item, item2,. . . itemN可选项。该 Array 的新元素。说明
    push 方法将以新元素出现的顺序添加这些元素。如果参数之一为数组,那么该数组将作为单个元素添加到数组中。如果要合并两个或多个数组中的元素,请使用 concat 方法。
      

  4.   

    如果觉得致真方便,就在你的程序加上unsafe{}
    这样就可以直接使用指针了。
    主要project中也要勾选上编译unsafe code项-
      

  5.   

    不用指针,就用ArrayList就可以了
    我上面不是有给MSDN的参考了吗
      

  6.   

    ArrayList我知道,不过我现在是要自己写一个Stack,可以存储任意大小的数据
      

  7.   

    jacobwc(倒娜特)用安全的指针委托
    在我的问题怎么用啊
    能给个小例子吗