Mega Code Archive

 
Categories / C# / Collections Data Structure
 

A Stacked array is an integer array that contains a sequence of ascending integers

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Common {     // A Stacked array is an integer array that contains a sequence of ascending integers.     // It is another representation of a bitset. Instead it contains the list of positions in the bitset that     // are set to true.     public class StackArrayUtility     {         public StackArrayUtility(int max)         {             _buffer = new int[max];         }         public int[] ToStackedArray(BitArray ba)          {             int j = 0;             for (int i = 0; i < ba.Length; i++)             {                 if (ba[i])                 {                     _buffer[j] = i;                     j++;                 }             }             int[] ret = new int[j];             for (int i = 0; i < j; i++)             {                 ret[i] = _buffer[i];             }             return ret;         }         public void FromStackedArray(int[] stack, BitArray ba)         {             for (int i = 0; i < stack.Length; i++)             {                 ba[i] = true;             }         }         #region private         private int[] _buffer = null;         #endregion     }      }