看板 C_and_CPP 關於我們 聯絡資訊
演算法本身就是錯的吧... 考慮 input[] = {3,1,2,3,4,5}; front last | | +---+---+---+---+---+---+ | 3 | 1 | 2 | 3 | 4 | 5 | +---+---+---+---+---+---+ meddle:3 因為 *last >= meddle 所以 last-- front last | | +---+---+---+---+---+---+ | 3 | 1 | 2 | 3 | 4 | 5 | +---+---+---+---+---+---+ meddle:3 again, *last >= meddle 所以 last-- front last | | +---+---+---+---+---+---+ | 3 | 1 | 2 | 3 | 4 | 5 | +---+---+---+---+---+---+ meddle:3 有等號的關係...again front last | | +---+---+---+---+---+---+ | 3 | 1 | 2 | 3 | 4 | 5 | +---+---+---+---+---+---+ meddle:3 跳出while(), swap(*front,*last); front last | | +---+---+---+---+---+---+ | 2 | 1 | 3 | 3 | 4 | 5 | +---+---+---+---+---+---+ meddle:3 接著 *front <= meddle 所以 front++ front last | | +---+---+---+---+---+---+ | 2 | 1 | 3 | 3 | 4 | 5 | +---+---+---+---+---+---+ meddle:3 直到 last front | | +---+---+---+---+---+---+ | 2 | 1 | 3 | 3 | 4 | 5 | +---+---+---+---+---+---+ meddle:3 然後 swap(*last,*front) last front | | +---+---+---+---+---+---+ | 2 | 1 | 4 | 3 | 3 | 5 | +---+---+---+---+---+---+ meddle:3 你會發現, 這個演算法根本就不正確... ̄▽ ̄|| -- 人家可不是為了你才這樣做的哦! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.198.35.85
nowar100:喔喔 有圖有推 XD 03/22 11:18
dendrobium:都是複製貼上啦XD 03/22 11:20
VictorTom:太熱心了, 推:) 03/22 11:23
mmmaaatttttt:推圖是一定要的啦XD 03/22 11:33
courant:有圖有推 03/22 11:39
loveme00835:有圖有推 03/22 15:26