From cc79ccab56a112b2e928bff63ce1d24cd2a22e22 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 2 Aug 2020 10:58:50 +0200 Subject: alten, seltsamen code zum Listensortieren entfernt. Eine Kopie davon gibt's in einem separaten Branch... --- dlist.c | 90 ----------------------------------------------------------------- 1 file changed, 90 deletions(-) diff --git a/dlist.c b/dlist.c index c006f20..5a11c5b 100644 --- a/dlist.c +++ b/dlist.c @@ -277,96 +277,6 @@ remove_if(struct dlist *list) } } -void -dlist_sort_xxx(struct dlist *list) -{ - if ( list->head == NULL ) - return; - - int insize = 1; - - while ( 1 ) { - struct dlist_element *p; - - p = list->head; - list->head = NULL; - list->tail = NULL; - - int nmerges = 0; /* count number of merges we do in this pass */ - - while ( p ) { - struct dlist_element *q; - - nmerges++; /* there exists a merge to be done */ - /* step `insize' places along from p */ - q = p; - int psize = 0; - for ( int i = 0; i < insize; i++ ) { - psize++; - q = q->next; - if ( !q ) - break; - } - - /* if q hasn't fallen off end, we have two lists to merge */ - int qsize = insize; - - /* now we have two lists; merge them */ - while ( psize > 0 || (qsize > 0 && q) ) { - struct dlist_element *e; - - /* decide whether next element of merge comes from p or q */ - if ( psize == 0 ) { - /* p is empty; e must come from q. */ - e = q; - q = q->next; - qsize--; - } - else if ( qsize == 0 || !q ) { - /* q is empty; e must come from p. */ - e = p; - p = p->next; - psize--; - } - else if ( p->data < q->data ) { - /* First element of p is lower ; - * e must come from p. */ - e = p; - p = p->next; - psize--; - } - else { - /* First element of q is lower; e must come from q. */ - e = q; - q = q->next; - qsize--; - } - - /* add the next element to the merged list */ - if ( list->tail ) { - list->tail->next = e; - } - else { - list->head = e; - } - e->prev = list->tail; - list->tail = e; - } - - /* now p has stepped `insize' places along, and q has too */ - p = q; - } - list->tail->next = NULL; - - /* If we have done only one merge, we're finished. */ - if ( nmerges <= 1 ) /* allow for nmerges==0, the empty list case */ - return; // list; - - /* Otherwise repeat, merging lists twice the size */ - insize *= 2; - } -} - struct dlist * dlist_merge(struct dlist *list1, struct dlist *list2) { -- cgit v1.3