Skip to content

Instantly share code, notes, and snippets.

@LizardLeliel
Created December 6, 2014 17:34
Show Gist options
  • Save LizardLeliel/1d150836b17c9047ca2c to your computer and use it in GitHub Desktop.
Save LizardLeliel/1d150836b17c9047ca2c to your computer and use it in GitHub Desktop.
Just a snippit to show someone
void pushSortedAdjNode(adjNode** listHead, int newID, int newDistance) {
adjNode* newNode = malloc(sizeof(adjNode));
newNode->id = newID;
newNode->distance = newDistance;
if (*listHead == NULL || (*listHead)->distance >= newDistance) {
newNode->next = *listHead;
*listHead = newNode;
return;
}
adjNode* temp = *listHead;
while ((*listHead)->next != NULL && (*listHead)->next->distance <= newDistance) {
*listHead = (*listHead)->next;
}
newNode->next = (*listHead)->next;
(*listHead)->next = newNode;
*listHead = temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment