Here we go!
template <class Record>void InsertionSort(Node<Record> *list){ if (list != NULL) { // "ls" means last sorted Node<Record> *ls = list; while (ls->next != NULL) { // "fu" means first unsorted Node<Record> *fu = ls->next; if (fu->data < list->data) { ls->next = fu->next; fu->next = list; list = fu; } else { Node<Record> *itr = list; Node<Record> *cur = itr->next; while (fu->data > cur->data) { itr = cur; cur = itr->next; }
if (fu == cur) { ls = fu; } else { ls->next = fu->next; fu->next = cur; itr->next = fu; } } } }}
Powered by: C++博客 Copyright © winter