/*----------------------------------------------------------------- here is the collection of all the methods for the linklist class -----------------------------------------------------------------*/ #include #include #include #include #include #include "DoubleList.h" #define MAXLIN 128 using namespace std; /*----------------------------------------------------------------- this method adds an double to the doublelist -----------------------------------------------------------------*/ int DoubleList::additem(double d) { if (barrier < 1) { cerr << "barrier in DoubleList is less than 1!! \n"; return (0); } if (AmountElements < barrier) { struct doublelink* newlink = new struct doublelink; newlink->dd = d; if (first == NULL && last == NULL) //List is empty { newlink->next = NULL; first = newlink; newlink->previous = NULL; last = newlink; value = d; AmountElements++; }else{ struct doublelink* current = first; while( current != NULL) { if (current->dd < newlink->dd) current = current->previous; else { if (current->next == NULL) //newlink is inserted at the the beginning { current->next = newlink; newlink->previous = current; newlink->next = NULL; first = newlink; }else //newlink is inserted in front of current { current->next->previous = newlink; newlink->next = current->next; newlink->previous = current; current->next = newlink; } value = first->dd; AmountElements++; break; } } if (current == NULL) { last->previous = newlink; newlink->previous = NULL; newlink->next = last; last = newlink; value = first->dd; AmountElements++; } current = NULL; } }else { if (value < d ) { first->dd = d; struct doublelink* current = first; while( current->previous != NULL) { if (current->dd > current->previous->dd) { current->dd = current->previous->dd; current->previous->dd = d; current = current->previous; } else { break; } } value = first->dd; current = NULL; } } return 1; } /*----------------------------------------------------------------- this method displays all evaluations of the evaluation list -----------------------------------------------------------------*/ void DoubleList::display() { if (first == NULL) cerr << "DoubleList is empty!!\n"; struct doublelink* current = first; cout << "Display of DoubleList: "; while( current != NULL) { cout << current->dd << " "; current = current->previous; } cout << " value: "<