//------------------------------------------------------------------------------ // // Demo execution // //------------------------------------------------------------------------------ int _tmain(int argc, _TCHAR* argv[]) { struct TestCase { int number; int median; }; const TestCase tests[] = { { 3, 3 }, { 5, 4 }, { 7, 5 }, { 1, 4 }, { 2, 3 }, }; Median median; for (int i = 0; i < ARRAYSIZE(tests); i++) { median.AddNewNumber(tests[i].number); int result = median.GetMedian(); cout << (result == tests[i].median ? "PASS" : "FAILED"); cout << ": Add " << tests[i].number; cout << ", Median is " << result << endl; } return 0; }
int main() { const int TEST_VALUE = 15; srand(unsigned (time(0))); Median<int> m; for (int i = 0; i < TEST_VALUE; ++i) { int num = rand() % 1000; m.addNum(num); } m.report(true); // print Heaps int size = 32; for (int i = TEST_VALUE; i < 1028; ++i) { int num = rand()%1000; //std::cout << num << " "; m.addNum(num); if (i == size) { m.report(false); size*=2; } } }
int main(){ Median mm; int A[] = {3, 6, 2, 7, 3, 1, 10, 9, 17}; int n = 9; for(int i = 0; i < n; ++i){ mm.insert(A[i]); } mm.get_size(); cout << mm.get_median() << endl; }
int main(void) { Median m; cout << "Please enter values " <<endl; while (!cin.eof()) { int value; cin >> value; m.insert(value); cout << "New median is " << m.getMedian() << endl; } return 0; }
int main (void) { std::vector<int> A = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; std::reverse(A.begin(), A.end()); std::cout << A << std::endl; Median<int> M; for (const auto& a: A) { debug(a); M.push(a); debug(M.getMedian()); } return 0; }
int main(){ srand((unsigned)time(NULL)); Median md; vector<int> vi; int num = rand() % 30; for(int i=0; i<num; i++){ int data = rand() % 100; vi.push_back(data); md.insert(data); } sort(vi.begin(), vi.end()); for(int i=0; i<num; i++){ cout<<vi.at(i)<<" "; } cout<<endl<<md.getValue()<<endl; return 0; }
TEST(Median, calculate) { Median<float> med; ASSERT_THROW(med.get(), std::exception); med.add(1); ASSERT_EQ(1, med.get()); med.add(2); ASSERT_EQ(1.5, med.get()); med.add(3); ASSERT_EQ(2, med.get()); med.add(99); ASSERT_EQ(2.5, med.get()); }
int main() { std::ios_base::sync_with_stdio(false); int T; cin >> T; for (auto t = 0; t < T; ++t) { uint64_t a, b, c, n; cin >> a >> b >> c >> n; uint64_t f_sum = 1; Median<uint64_t> median; median.add(1); for (auto i = 2; i <= n; ++i) { auto f = (a*median.get() + b*i + c) % MOD; median.add(f); f_sum += f; } cout << f_sum << endl; } }