| 497 | } |
| 498 | |
| 499 | void sort() { |
| 500 | // Insertion sort for simplicity (appropriate for embedded systems) |
| 501 | if (mSize <= 1) { |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | Node* sorted_end = mHead->next; |
| 506 | |
| 507 | while (sorted_end->next != mHead) { |
| 508 | Node* current = sorted_end->next; |
| 509 | |
| 510 | // Find insertion point in sorted portion |
| 511 | Node* insert_pos = mHead->next; |
| 512 | while (insert_pos != sorted_end->next && insert_pos->data < current->data) { |
| 513 | insert_pos = insert_pos->next; |
| 514 | } |
| 515 | |
| 516 | // If current is already in correct position |
| 517 | if (insert_pos == current) { |
| 518 | sorted_end = current; |
| 519 | } else { |
| 520 | // Remove current from its position |
| 521 | unlink(current); |
| 522 | // Insert before insert_pos |
| 523 | link_before(insert_pos, current); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | template<typename Compare> |
| 529 | void sort(Compare comp) { |
no outgoing calls