A Stacked array is an integer array that contains a sequence of ascending integers. : Stack « Collections Data Structure « C# / C Sharp






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
    }
    


}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.new Stack(new int[] { 1, 2, 3, 4, 5, 6 })
2.new Stack())
3.Implements the stack data type using an arrayImplements the stack data type using an array
4.Stack demo Stack demo
5.Stack to arrayStack to array
6.illustrates the use of a Stackillustrates the use of a Stack
7.A stack class for charactersA stack class for characters
8.Demonstrate the Stack classDemonstrate the Stack class
9.Stack(T) Class represents a variable size last-in-first-out (LIFO) collection of instances of the same arbitrary type.
10.Overflow Stack
11.Thread Safe Stack
12.FixedSizeStack provides an easy Stack implementation width a fixed size to prevent Stack Overflows in another sense.
13.Stack abstraction that also supports the IList interface