Реализация линейной структуры данных и оценка эффективности работы со структурой в зависимости от размерности структуры, страница 4

                                       return n;

                                       }

                    do

                                       {

                                       if (c==0) break;

                                       c--;

                                       cur=cur->next;

                                       cntDelete++;

                                       }

                    while (cur != first);

                    if (cur == first) return -1;

                    if (cur == last)

                                       {

                                       tmp=last;

                                       last=last->prev;

                                       last->next=first;

                                       first->prev=last;

                                       delete tmp;

                                       cnt--;

                                       cntDelete+=6;

                                       return n;

                                       }

                    tmp=cur;

                    cur->prev->next = cur->next;

                    cur->next->prev = cur->prev;

                    delete tmp;

                    cntDelete+=3;

                    cnt--;

                    return n;

}

//----------------------------------------------------

template<class T>

void CList<T>::Test(int SizeOfStructure)

{

                    cout<<"Testing..."<<endl;

                    int value = 0;

                    srand(10000);

                    cout<<">"<<endl;

                    for (int j = 0; j < SizeOfStructure; j++)

                    {

                                       value = rand()/100;

                                       Insert(value);

                    }

                    cntFind = cntInsert = cntDelete = 0;

                    int size = ListSize();

                    cout<<size<<" elements in structure"<<endl;

                    int range;                                          //Промежуток значений, генерируемых генератором случ. чисел

                    int cntIns, cntRem, cntFin;//Счётчики кол-ва запусков соотвеств. методов

                    cntIns = cntRem = cntFin = 0;

                    for (int i = 0; i<size*2; i++)            //Количество операций в два раза больше размера структуры

                    {

                                       range = rand()%1000; //Генерируем числа в диапазоне [0;1000] для псевдослучайного выбора

                                       //операции над структурой

                                       value = rand()%(SizeOfStructure/10);//Генерируем числа в диапазоне,

                                       //меньшем на порядок первоначального размера структуры. Таким образом достигается

                                       //баланс между вставками и удалениями.

                                       if (range<333) {cntIns++; Insert(value);}

                                                           else

                                                                               if ( range < 666 ) {cntRem++; Delete(value);}

                                                                               else

                                                                                                  if (range <= 1000)       {cntFin++; GetData(value);}

                    }

//Анализ результатов

                    int AllOperations = cntFind + cntRem + cntIns; //Всего операций было выполнено

                    int sizeAfter = ListSize();               //Новый размер структуры

                    float sizeDiff = 0;

                    sizeDiff = (abs((float)size - (float)sizeAfter)/(float)size)*100;