// algo/shuffle1.cpp
#include #include "algostuff.hpp" using namespace std;
int main() { vector coll;
INSERT_ELEMENTS(coll,1,9); PRINT_ELEMENTS(coll,"coll: ");
// shuffle all elements randomly random_shuffle (coll.begin(), coll.end());
PRINT_ELEMENTS(coll,"shuffled: ");
// sort them again sort (coll.begin(), coll.end()); PRINT_ELEMENTS(coll,"sorted: ");
// shuffle elements with default engine default_random_engine dre; shuffle (coll.begin(), coll.end(), // range dre); // random-number generator
PRINT_ELEMENTS(coll,"shuffled: ");
}
/ / algo/shuffle1.cpp
#include #include "algostuff.hpp" ใช้ namespace มาตรฐาน;
int main() { coll;
INSERT_ELEMENTS(coll,1,9) เวกเตอร์ PRINT_ELEMENTS (coll, " coll: ") ;
// shuffle องค์ประกอบทั้งหมดสุ่ม random_shuffle (coll.begin(), coll.end());
PRINT_ELEMENTS (coll, "สับ: ") ;
//เรียงอีกเรียงลำดับ (coll.begin(), coll.end()) PRINT_ELEMENTS (coll, "เรียงลำดับ: ");
/ / shuffle องค์ประกอบ ด้วยค่าเริ่มต้นเครื่องยนต์เดร default_random_engine สลับ (coll.begin(), coll.end(), / / ช่วงเดร); / / เลขสุ่มกำเนิด
PRINT_ELEMENTS (coll, "สับ: ");
}
การแปล กรุณารอสักครู่..
