void partition(Listp hd, int v) { tassume(" dll(?k,null,hd,?end,null)"); Listp next = 0, prev = 0; int tmp; Listp curr = hd, less = 0, more = 0; hd = 0; while( curr != 0 ) { tmp = curr->data; if( tmp >= v ) { /* add to more */ next = curr->n; curr->n = more; if( more != 0 ) more->b = curr; more = curr; more->b = 0; curr = next; } else { /* add to less */ next = curr->n; curr->n = less; if( less != 0 ) less->b = curr; less = curr; less->b = 0; curr = next; } if( curr != 0 ) curr->b = 0; } return; }