void Vlist::print_by_rating() { Node *ptr = vlist_head; Node *temp = vlist_head; for (int loops = length(); loops > 0; loops--) { for (int current = 0; current < loops; current++) { ptr = vlist_head; temp = vlist_head; while (ptr->vlist_next != NULL && ptr->vlist_video->get_rating() >= ptr->vlist_next->vlist_video->get_rating()) { temp = ptr; ptr = ptr->vlist_next; } if (ptr == vlist_head) { vlist_head = vlist_head->vlist_next; ptr->vlist_next = vlist_head->vlist_next; vlist_head->vlist_next = ptr; } else if (ptr->vlist_next != NULL) { temp->vlist_next = ptr->vlist_next; ptr->vlist_next = ptr->vlist_next->vlist_next; temp->vlist_next->vlist_next = ptr; } } } print(); fix_list(); }
void main(){ for (int i = 0; i < 2; i++){ fix_list(numberToLinkedList(test[i].input)); } _getch(); }