Пример #1
0
        private String testHeap(int lengthA, int lenghtB, int rangeA, int rangeB, int size)
        {
            int insertArrayLength = lengthA;
            int removeAndInsertArrayLength = lenghtB;
            int insertRange = rangeA;
            int removeAndInsertRange = rangeB;

            Element[] elementM = new Element[insertArrayLength];
            Element[] elementN = new Element[removeAndInsertArrayLength];
            Random rnd = new Random();
            int tmp = 0;
            while (tmp < insertArrayLength)
            {
                elementM[tmp] = new Element(rnd.Next(1, insertRange + 1));
                tmp++;
            }

            tmp = 0;
            while (tmp < removeAndInsertArrayLength)
            {
                elementN[tmp] = new Element(rnd.Next(1, removeAndInsertRange + 1));
                tmp++;
            }

            Stopwatch watch = new Stopwatch();
            watch.Start(); //czy tutaj włączyć czy przy inicjalizacji randomów?
            Heap heap = new Heap(size);

            for (tmp = 0; tmp < insertArrayLength; tmp++)
            {
                heap.insert(elementM[tmp]);
            }
            tmp = 0;
            while (tmp < removeAndInsertArrayLength)
            {

                heap.deleteMin();
                heap.insert(elementN[tmp]);
                tmp++;
            }
            watch.Stop();

            return watch.Elapsed.ToString(); //watch.ElapsedMilliseconds.ToString();
        }
Пример #2
0
 public void insert(Element element)
 {
     myArray[++index]=element;
 }