\begin{algorithm} \caption{Reverse Singly Linked List} \begin{algorithmic} \INPUT a singly linked list $L$ with $L.head$ pointing to its first element \OUTPUT a reversed singly linked list $L$ \STATE $prev = NIL$ \STATE $cur = L.head$ \WHILE{$cur \ne NIL$} \STATE $next = cur.next$ \STATE $cur.next = prev$ \STATE $prev = cur$ \STATE $cur = next$ \ENDWHILE \STATE $L.head = prev$ \end{algorithmic} \end{algorithm}