作者lionel20002 (~小遙~)
看板EE_DSnP
標題[閒聊] C++ Algorithms
時間Tue Dec 4 00:32:15 2007
發現 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
1F:推 ric2k1:This is cool... I didn't know that. The complexity is 12/04 00:36
2F:→ ric2k1:linear for one sort, so the total will be quadric. 12/04 00:36
3F:噓 ric2k1:想錯了, 是 n*n!... 太慢囉... 12/04 00:39
4F:→ lionel20002:非遞迴會比遞迴慢?? 12/04 09:54
5F:推 ric2k1:遞迴應該比較慢, 其實 n*n! 也還OK啦, 12/04 10:49
6F:→ ric2k1:不知道有沒有快一點的 algorithm? 12/04 10:50
7F:推 lionel20002:仿造了next_permutation()的功用自己寫了一個函式 12/04 17:26
8F:→ lionel20002:只用了迴圈,而且也不複雜(fuction本身約25行) 12/04 17:28
9F:→ lionel20002:大家可以往這個方向想想看!就能寫出非遞迴排列了 12/04 17:29
10F:推 ric2k1:That's a good hint! Thank you. 12/04 19:05