#include #include using namespace std ; #include "IntLink.h" IntLink* genNormalList(int Size) { IntLink* theLink = NULL ; for (int i = Size-1; i >= 0 ; --i) theLink = new IntLink(i, theLink) ; return theLink ; } IntLink* genLollypop(int Size, int LoopSize) { // Assuming 1 <= LoopSize <= Size IntLink* theTail = new IntLink(Size-1) ; if (LoopSize == 1) theTail->next = theTail ; IntLink* theLink = theTail ; for (int i = Size-2; i >= 0 ; --i) { theLink = new IntLink(i, theLink) ; if (i == (Size-LoopSize)) theTail->next = theLink ; } return theLink ; } int increasingList(IntLink* theList) { int listOK = 1 ; // Test the list int countUp = 0 ; IntLink* head = theList ; while ((head != NULL) && listOK) { if (head->element != countUp) listOK = false ; head = head->next ; countUp++ ; } return listOK ; } void main(int argc, char *argv[]) { cout << "Straight Loop [1,000,000]: " << increasingList(genNormalList(1000000)) << endl ; cout.flush() ; cout << "Lollypop [1,000,000 = 100,000]: " << increasingList(genLollypop(1000000,100000)) << endl ; cout.flush() ; cout << "Lollypop [1,000,000 = 900,000]: " << increasingList(genLollypop(1000000,900000)) << endl ; cout.flush() ; }