From a916d036f20db60575f2231f06831770fb96415f Mon Sep 17 00:00:00 2001 From: Stefan Kremser Date: Sat, 21 Apr 2018 22:32:18 +0200 Subject: [PATCH] Updated SimpleList --- esp8266_deauther/SimpleList.h | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/esp8266_deauther/SimpleList.h b/esp8266_deauther/SimpleList.h index ffd2a1e..b0be3b4 100644 --- a/esp8266_deauther/SimpleList.h +++ b/esp8266_deauther/SimpleList.h @@ -337,25 +337,27 @@ void SimpleList::swap(int x, int y){ template void SimpleList::sort(bool (*cmp)(T &a, T &b)) { - // bubble sort :D - - Node* nodeA; - Node* nodeB; - - int c = listSize-1; - bool swapped = true; - while(c > 0 && swapped){ - swapped = false; - for(int i = 0; i < c; i++){ - nodeA = getNode(i); - nodeB = getNode(i+1); + // selection sort - if(cmp(nodeA->data, nodeB->data)) { - swap(i,i+1); - swapped = true; + int indexA; + int indexB; + Node* nodeA; // node at index i + Node* nodeB; // next minimum node + Node* nodeH; // helper node at index j + + for(int i=0; idata, nodeH->data)){ + nodeB = nodeH; + indexB = j; } } - c--; + swap(indexA, indexB); } }