摘要: AnalysisFor a list withnitems, the best case is when the value is equal to the first element of the list, in which case only one comparison is needed. The worst case is when the value is not in the list (or occurs only once at the end of the list), in which casencomparisons are needed.If the value b 阅读全文
posted @ 2011-02-11 16:12 lcfigu 阅读(823) 评论(0) 推荐(0) 编辑
摘要: Bubble sort, also known assinking sort, is a simplesorting algorithmthat works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items andswappingthem if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates 阅读全文
posted @ 2011-02-11 15:48 lcfigu 阅读(1236) 评论(0) 推荐(0) 编辑
摘要: The algorithm works as follows:1. Find the minimum value in the list2. Swap it with the value in the first position3. Repeat the steps above for the remainder of the list (starting at the second position and advancing each time)Effectively, the list is divided into two parts: the sublist of items al 阅读全文
posted @ 2011-02-11 14:32 lcfigu 阅读(661) 评论(0) 推荐(0) 编辑