i have a linked list and for some reason the following 2 fucntions work fine
Command 11 : PRINT_LISTCode:void NodeList::printList() { StudentNode* walk = first; int num = 0; if(listSize()> 0) { while(walk != NULL) { num++; cout<<"["<<num<<"] "<<walk->thisStudent<<endl; walk = walk->next; } } else { cout<<"The list is Empty"; } } void NodeList::printListReverse() { StudentNode* walk = last; int num = 0; if(listSize()> 0) { while(walk != NULL) { num++; cout<<"["<<num<<"] "<<walk->thisStudent<<endl; walk = walk->prev; } } else { cout<<"The list is Empty"; } }
[1] xavior, GPA = 4.90, JagID = J00000001
[2] willy, GPA = 3.55, JagID = J00084689
[3] jill, GPA = 3.24, JagID = J00003512
[4] ben, GPA = 4.00, JagID = J00024040
[5] timmy, GPA = 1.00, JagID = J00418564
Command 12 : PRINT_LIST_REVERSE
[1] timmy, GPA = 1.00, JagID = J00418564
[2] bigelow, GPA = 4.00, JagID = J00024040
[3] jill, GPA = 3.24, JagID = J00003512
[4] willy, GPA = 3.55, JagID = J00084689
[5] xavior, GPA = 4.90, JagID = J00000001
but when i print reading my indexes i get this stuff:
the code for each index is:
prints out :Code:void NodeList::printListName() { indexName(); StudentNode* walk = firstName; int num = 0; if(listSize()> 0) { while(walk != NULL) { num++; cout<<"["<<num<<"] "<<walk->thisStudent<<endl; walk = walk->nextName; } } else { cout<<"The list is Empty"; } } void NodeList::indexName() { StudentNode* walk = first; StudentNode* walkName = NULL; StudentNode* newguy = NULL; StudentNode* temp = NULL; while(firstName != NULL) { temp = firstName; firstName = firstName->next; temp->nextName = NULL; } lastName = firstName = NULL; while(walk != NULL) { walkName=firstName; newguy = walk; if(firstName == NULL) { firstName = newguy; lastName = newguy; newguy->nextName = NULL; } else if (newguy->thisStudent.name <= firstName->thisStudent.name) { newguy->nextName = firstName; firstName = newguy; } else if (newguy->thisStudent.name > lastName->thisStudent.name) { lastName->nextName = newguy; lastName = newguy; lastName->nextName = NULL; } else { while(newguy->thisStudent.name > walkName->nextName->thisStudent.name) { walkName = walkName->nextName; } newguy->nextName = walk->nextName; walk->nextName = newguy; } walk = walk->next; } }
Command 13 : PRINT_LIST_NAME
[1] ben, GPA = 4.00, JagID = J00024040
[2] jill, GPA = 3.24, JagID = J00003512
[3] willy, GPA = 3.55, JagID = J00084689
[4] xavior, GPA = 4.90, JagID = J00000001
prints out:Code:void NodeList::printListGPA() { indexGPA(); StudentNode* walk = firstGPA; int num = 0; if(listSize()> 0) { while(walk != NULL) { num++; cout<<"["<<num<<"] "<<walk->thisStudent<<endl; walk = walk->nextGPA; } } else { cout<<"The list is Empty"; } } void NodeList::indexGPA() { StudentNode* walk = first; StudentNode* walkGPA = NULL; StudentNode* newguy = NULL; StudentNode* temp = NULL; while(firstGPA != NULL) { temp = firstGPA; firstGPA = firstGPA->next; temp->nextGPA = NULL; } lastGPA = firstGPA = NULL; while(walk != NULL) { walkGPA=firstGPA; newguy = walk; if(firstGPA == NULL) { firstGPA = newguy; lastGPA = newguy; newguy->nextGPA = NULL; } else if (newguy->thisStudent.gpa <= firstGPA->thisStudent.gpa) { newguy->nextGPA = firstGPA; firstGPA = newguy; } else if (newguy->thisStudent.gpa > lastGPA->thisStudent.gpa) { lastGPA->nextGPA = newguy; lastGPA = newguy; lastGPA->nextGPA = NULL; } else { while(newguy->thisStudent.gpa > walkGPA->nextGPA->thisStudent.gpa) { walkGPA = walkGPA->nextGPA; } newguy->nextGPA = walk->nextGPA; walk->nextGPA = newguy; } walk = walk->next; } }
Command 14 : PRINT_LIST_GPA
[1] timmy, GPA = 1.00, JagID = J00418564
[2] jill, GPA = 3.24, JagID = J00003512
[3] willy, GPA = 3.55, JagID = J00084689
[4] xavior, GPA = 4.90, JagID = J00000001
prints out:Code:void NodeList::printListJAG() { indexJAG(); StudentNode* walk = firstJAG; int num = 0; if(listSize()> 0) { while(walk != NULL) { num++; cout<<"["<<num<<"] "<<walk->thisStudent<<endl; walk = walk->nextJAG; } } else { cout<<"The list is Empty"; } } void NodeList::indexJAG() { StudentNode* walk = first; StudentNode* walkJAG = NULL; StudentNode* newguy = NULL; StudentNode* temp = NULL; while(firstJAG != NULL) { temp = firstJAG; firstJAG = firstJAG->next; temp->nextJAG = NULL; } lastJAG = firstJAG = NULL; while(walk != NULL) { walkJAG=firstJAG; newguy = walk; if(firstJAG == NULL) { firstJAG = newguy; lastJAG = newguy; newguy->nextJAG = NULL; } else if (newguy->thisStudent.jagID <= firstJAG->thisStudent.jagID) { newguy->nextJAG = firstJAG; firstJAG = newguy; } else if (newguy->thisStudent.jagID > lastJAG->thisStudent.jagID) { lastJAG->nextJAG = newguy; lastJAG = newguy; lastJAG->nextJAG = NULL; } else { while(newguy->thisStudent.jagID > walkJAG->nextJAG->thisStudent.jagID) { walkJAG = walkJAG->nextJAG; } newguy->nextJAG = walk->nextJAG; walk->nextJAG = newguy; } walk = walk->next; } }
Command 15 : PRINT_LIST_JAG
[1] xavior, GPA = 4.90, JagID = J00000001
[2] willy, GPA = 3.55, JagID = J00084689
[3] timmy, GPA = 1.00, JagID = J00418564
i could under stand if they all printed out the same number of items. but im baffled that one list would print out all but 2 when i did a block copy and changed variables.



LinkBack URL
About LinkBacks


