看板 EE_DSnP 關於我們 聯絡資訊
發現 C++ Algorithms 裡面有兩個關於排列的函式 bool next_permutation(iterator start,iterator end); 這個函式會幫你排下一個permutation bool prev_permutation(iterator start,iterator end); 這個會排上一個permutation 用這個寫超快的(大誤) PS.以上純屬娛樂,自己玩玩就好- - PS2.我論:C++ Algorithms真是太強大了啊!(讚嘆) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.240.249
ric2k1:This is cool... I didn't know that. The complexity is 12/04 00:36
ric2k1:linear for one sort, so the total will be quadric. 12/04 00:36
ric2k1:想錯了, 是 n*n!... 太慢囉... 12/04 00:39
lionel20002:非遞迴會比遞迴慢?? 12/04 09:54
ric2k1:遞迴應該比較慢, 其實 n*n! 也還OK啦, 12/04 10:49
ric2k1:不知道有沒有快一點的 algorithm? 12/04 10:50
lionel20002:仿造了next_permutation()的功用自己寫了一個函式 12/04 17:26
lionel20002:只用了迴圈,而且也不複雜(fuction本身約25行) 12/04 17:28
lionel20002:大家可以往這個方向想想看!就能寫出非遞迴排列了 12/04 17:29
ric2k1:That's a good hint! Thank you. 12/04 19:05