Ejemplo n.º 1
0
        public static int[] SearchPrimesUseBitArrayGaijin(int min, int max)
        {
            ListMy <int> tempInts   = new ListMy <int>();
            BitArrayMy   bitArrayMy = new BitArrayMy(max);

            bitArrayMy.SetAll(true);
            bitArrayMy.Set(0, false);
            bitArrayMy.Set(1, false);

            int upper = (int)Math.Sqrt(max);

            for (int i = 2; i < upper + 1; i++)
            {
                for (int j = i + 1; j < max; j++)
                {
                    if (bitArrayMy.Get(j) && j % i == 0)
                    {
                        bitArrayMy.Set(j, false);
                    }
                }
            }

            for (int i = min; i < max; i++)
            {
                if (bitArrayMy.Get(i))
                {
                    tempInts.Add(i);
                }
            }

            return(tempInts.ToArray());
        }
Ejemplo n.º 2
0
        public BitArrayMy(byte[] bytes)
        {
            _listMyBit = new ListMy <bool>(bytes.Count());
            for (int i = 0; i < bytes.Length; i++)
            {
                string tempString = ConverByteToBitsString(bytes[i]);
                for (int j = 0; j < tempString.Length; j++)
                {
                    bool tempBool = false;
                    if (tempString.Substring(j, 1) == "1")
                    {
                        tempBool = true;
                    }

                    _listMyBit.Add(tempBool);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 用数组寻找素数的方法
        /// </summary>
        /// <param name = "min" ></ param >
        /// < param name="max"></param>
        /// <returns></returns>
        public static int[] SearchPrimes(int min, int max)
        {
            ListMy <int> tempList = new ListMy <int>();

            int[] tempInts = new int[max];
            tempInts[0] = 0;
            tempInts[1] = 0;
            for (int i = 2; i < max; i++)
            {
                tempInts[i] = 1;
            }

            for (int i = 2; i < max; i++)
            {
                for (int j = i + 1; j < max; j++)
                {
                    if (tempInts[j] == 1 && j % i == 0)
                    {
                        tempInts[j] = 0;
                    }
                }
            }

            //Console.WriteLine("在范围{0}到{1}之间,所有的素数为:",min,max);
            for (int i = min; i < max; i++)
            {
                int temp = tempInts[i];
                if (temp == 1)
                {
                    //Console.Write(i + "  ");
                    tempList.Add(i);
                }
            }

            return(tempList.ToArray());
        }
Ejemplo n.º 4
0
 public BitArrayMy(int capacity)
 {
     _listMyBit = new ListMy <bool>(capacity);
 }
Ejemplo n.º 5
0
 public BitArrayMy()
 {
     _listMyBit = new ListMy <bool>();
 }
Ejemplo n.º 6
0
        public StackMy()
        {
            Stack <int> test = new Stack <int>();

            _stackData = new ListMy <T>();
        }
Ejemplo n.º 7
0
 public DictionaryMy()
 {
     _listMyKeys   = new ListMy <TKey>();
     _listMyValues = new ListMy <TValue>();
 }
Ejemplo n.º 8
0
 public SortedListMy()
 {
     _listMyKeys   = new ListMy <TKey>();
     _listMyValues = new ListMy <TValue>();
 }
Ejemplo n.º 9
0
 public QueueMy(int capacity)
 {
     _queueData = new ListMy <T>(capacity);
 }
Ejemplo n.º 10
0
 public QueueMy()
 {
     _queueData = new ListMy <T>();
 }