Skip to content

Instantly share code, notes, and snippets.

@paullewallencom
Created July 27, 2018 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paullewallencom/88a431f8ba2041e8637ab758039a4379 to your computer and use it in GitHub Desktop.
Save paullewallencom/88a431f8ba2041e8637ab758039a4379 to your computer and use it in GitHub Desktop.
C++ List Insertion Sort
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