Re: [問題] File Merge sort

看板C_and_CPP (C/C++)作者 (pziyout)時間16年前 (2009/03/25 09:11), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《d9003000 ()》之銘言: : 請教各位大大: : 我想寫一個先從二個FILE裡都讀一個數字出來~ : 然後來做比較~ : 比較小的數字就存入第三個檔案裡~ : 譬如: a檔裡面有1,2,9 : b檔裡面有7,4,11 : 1跟7比 然後把1存到第3個檔 : 2跟7比 然後把2存到第3個檔 : 9跟7比 然後把7存到第3個檔 : .. : 以此類推.... 大砲打小鳥的方法: #include <iostream> #include <fstream> #include <algorithm> #include <iterator> #include <vector> using namespace std ; int main() { ifstream f1("data1") , f2("data2") ; ofstream f3("data3") ; vector<int> a , b ; istream_iterator<int> itr1(f1) , itr2(f2) ; ostream_iterator<int> otr(f3," ") ; copy( itr1 , istream_iterator<int>() , back_inserter(a) ) ; copy( itr2 , istream_iterator<int>() , back_inserter(b) ) ; sort( a.begin() , a.end() ) ; sort( b.begin() , b.end() ) ; merge( a.begin() , a.end() , b.begin() , b.end() , otr ) ; return 0 ; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.25.24

03/25 09:20, , 1F
STL 我推 +1
03/25 09:20, 1F
文章代碼(AID): #19oOIeWN (C_and_CPP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
文章代碼(AID): #19oOIeWN (C_and_CPP)