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

                                       if (*q->elem > *p->elem) {tmp->elem = q->elem; q->elem = p->elem; p->elem = tmp->elem;}

                                       q=q->next;

                                       p=p->next;

                                       }

                    while (p != first);

                    }

}

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

template <class T>

T List <T>::GetData(int n)

{

                    if (n < 1) return -1;

                    int c = n;

                    Elem <T> *q = first;

                    if (c == 1) return *first->elem;

else

                    {

                                       do

                                       {

                                       q=q->next;

                                       c--;

                                       cntFind++;

                                       if (c==0) return *q->elem;

                                       }while (q != first);

                    }

return -1;

}

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

template <class T>

Elem<T>* List <T>::Find_num(int n)

{

    int c = n;

                    Elem <T> *q = first;

                    cntFind++;

                    if (c == 1) return first;

                                       do

                                       {

                                       q=q->next;

                                       c--;

                                       if (c==0) return q;

                                       }while (q != first);

                    return NULL;

}

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

template <class T>

int List <T>::Find(T dat)

{

                    Elem <T> *q = first;

                    do

                                       {

                                       if (*q->elem == dat) return 1;

                                       q=q->next;

                                       }

                    while(q != first);

                    return -1;

}

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

template <class T>

int List <T>::GetPos(T dat)

{

    int pos=0;

                    Elem <T> *q = first;

                    do

                                       {

                                                           if (*q->elem == dat) return pos;

                                                           q=q->next;

                                                           pos++;

                                       }

   while (q != first);

return -1;

}

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

template <class T>

void List <T>::ClearList()

{

    Elem <T> *q = first;

                    Elem <T> *del;

                    do

                                       {

                                                           del=q;

                                                           q=q->next;

                                                           delete del;

                                       }

   while (q != first);

}

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

template <class T>

void CList<T>::Insert(T n)//упорядоченая вставка

{

                    T *d = new T(n);

                    Elem <T> *e = new Elem <T>(d);

                    Elem <T> *cur = first;

                    cntInsert++;

                    if (first == NULL)

                                       {

                                       first = last = e;

                                       first->next = first->prev = last;

                                       last->next = last->prev = first;

                                       cnt++;