Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void list_ins_aft ( node_t *old ,node_t *new )
- {
- if ( old->next != NULL )
- {
- old->next->prev = new;
- }
- new->next = old->next;
- new->prev = old ;
- old->next = new ;
- }
- void list_detach( node_t *n , dlist_t *nlst)
- {
- if (n->prev == NULL)
- {
- nlst->head = n->next;
- }
- else
- {
- n->prev->next = n->next;
- }
- if(n->next == NULL )
- {
- nlst->tail = n->prev;
- }
- else
- {
- n->next->prev = n->prev;
- }
- }
- void qsort_segment ( node_t *t1 , node_t *t2 , dlist_t *lst)
- {
- /* skip 0 or 1 lengh segment */
- if ( t1 == t2 || t1->next == t2 )
- return;
- /*define pivot and make sure its the first element
- * so put the less before pivot and bigger after pivot
- * */
- node_t *piv;
- piv = t1->next;
- node_t *s,*b,*temp = piv , *x = t2 ? t2->next : NULL ;
- for ( s = piv->next ; s != x ; s = b )
- {
- b = s->next ;
- list_detach ( s ,lst ) ;
- if ( s->value < piv->value )
- {
- list_ins_aft(t1 , s );
- }
- else
- {
- list_ins_aft ( piv , temp == piv ? ( temp = s ) : s );
- }
- }
- /* now sort new segments on right and left sides of pivot the same way */
- qsort_segment ( piv , temp ,lst );
- qsort_segment ( t1 , piv->prev , lst);
- }
- /*define pivot and make sure its the first element
- * so put the less before pivot and bigger after pivot
- * */
- node_t *piv;
- piv = t1->next;
- if ( s->value < piv->value )
- {
- list_ins_aft(t1 , s );
- }
Add Comment
Please, Sign In to add comment