Skip to content

Instantly share code, notes, and snippets.

@adawolfa
Created June 7, 2022 18:11
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 adawolfa/b06cbb3a63d27fc384ee45e999319d5c to your computer and use it in GitHub Desktop.
Save adawolfa/b06cbb3a63d27fc384ee45e999319d5c to your computer and use it in GitHub Desktop.
<?php
function reverse_linked_list(Node &$node): void
{
for (
$current = $node,
$previous = null,
$following = $current->next;
$current !== null;
$previous = $current,
$current = $following,
$following = $current->next ?? null
) {
$current->next = $previous;
$node = $current;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment