LinkedList Reversal

Reversing a LinkedList is sometimes necessary. Usually when building a LinkedList it is possible insert the elements in a reverse order. However since this is not always the case there is a simple solution to reverse a LinkedList.

package { 	public interface ILinkedListElement { 		function get next: ILinkedListElement; function set next( value: ILinkedListElement ); } }

function reverse( start: ILinkedListElement ): void { 	var p: ILinkedListElement = start; var pr: ILinkedListElement; var pt: ILinkedListElement; while( p ) { 		pt = p.next; p.next = pr; pr = p; 		p = pt; } }