标签:style blog color io os strong sp div on
题目:给出O(N)运行时间的非递归算法,实现对一个含N个元素的链表的逆转,要求空间复杂度为O(1)
代码:
/* Assuming List with header and L is not empty */ List ReverseList( List L ) { Position CurrentPos, NextPos; NextPos = L->Next; L->Next = NULL; while ( NextPos != NULL ) { CurrentPos = NextPos; NextPos = NextPos->Next; CurrentPos->Next = L->Next; L->Next = CurrentPos; } }
标签:style blog color io os strong sp div on
原文地址:http://www.cnblogs.com/tallisHe/p/4033011.html