Created
July 27, 2018 04:13
-
-
Save paullewallencom/88a431f8ba2041e8637ab758039a4379 to your computer and use it in GitHub Desktop.
C++ List Insertion Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct node heada, headb; | |
link t, u, x, a = &heada, b; | |
for ( i = 0, t = a; i < N; i++ ) | |
{ | |
t->next = malloc( sizeof *t ); | |
t = t->next; t->next = NULL; | |
t->item = rand() % 1000; | |
} | |
b = &headb; b->next = NULL; | |
for ( t = a->next; t != NULL; t = u ) | |
{ | |
u = t->next; | |
for ( x = b; x->next != NULL; x = x->next ) | |
if ( x->next->item > t->item ) break; | |
t->next = x->next; x->next = t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment