using System; using System.Diagnostics; using System.Linq;
public static class Program
public static void PushStringCopyArray(ref string[] array, string pushvalue)
string[] temp = new string[array.Length];
Array.Copy(array, 0, temp, 1, array.Length-1);
public static void PushStringArray(ref string[] array, string pushvalue)
string[] temp = new string[array.Length];
for (int i = 0; i < array.Length - 1; i++)
public static string PopStringArray(ref string[] array)
string[] temp = Enumerable.Repeat("#", array.Length).ToArray();
string popvalue = array[0];
for (int i = array.Length - 1; i >= 1; i--)
public static void PrintArray(ref string[] array)
for (int i = 0; i < array.Length; i++)
Console.Write("a["+i+"]="+array[i]+",");
public static void Main()
Stopwatch sw = new Stopwatch();
string[] test = new string[]{"z","a","b","c"};
Console.WriteLine("Pop/Push Array Test");
Console.WriteLine("Arr Len="+test.Length);
PushStringArray(ref test, "1st");
PushStringArray(ref test, "2nd");
PushStringArray(ref test, "3rd");
PushStringArray(ref test, "4th");
Console.WriteLine(sw.ElapsedTicks+" ticks. WOW! For loop, but still O(n).");
PushStringCopyArray(ref test, "5th");
Console.WriteLine(sw.ElapsedTicks+" ticks. Array.Copy: I thought this would be better.");
Console.WriteLine(PopStringArray(ref test));
Console.WriteLine(PopStringArray(ref test));
Console.WriteLine(PopStringArray(ref test));
Console.WriteLine(PopStringArray(ref test));
Console.WriteLine(PopStringArray(ref test));