Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Node {
- Node * next;
- int data;
- };
- #include "solution.h"
- #include <cassert>
- #include <climits>
- #include <cstdlib>
- #include <iostream>
- #define N 10050060
- int main() {
- assert(sizeof(Node) <= 16);
- LinkedList odd(N);
- LinkedList even(N);
- srand(42);
- for (int i = 0; i != N; ++i) {
- int x = rand();
- if (x % 2 == 0) {
- even.push_front(x);
- } else {
- odd.push_front(x);
- }
- }
- long long sum = 0;
- long long min = LONG_MAX;
- long long max = 0;
- {
- const Node *node = odd.head();
- while (node) {
- sum += node->data;
- node = node->next;
- }
- }
- {
- const Node *node = odd.head();
- while (node) {
- if (node->data < min) {
- min = node->data;
- }
- node = node->next;
- }
- }
- {
- const Node *node = odd.head();
- while (node) {
- if (node->data > max) {
- max = node->data;
- }
- node = node->next;
- }
- }
- std::cout << sum << ' ' << min << ' ' << max << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment