Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <locale.h>
- #include <windows.h>
- #include <time.h>
- struct list {
- list(char _n = 0, short _a = 0, list *_next = NULL) : n(_n), a(_a), next(_next) { }
- char n;
- short a;
- list *next;
- };
- char random();
- void sumLists(list* r, list *a, list *b);
- list* fillList(char index, list* next = NULL);
- const char N = 10;
- int main()
- {
- time_t t;
- srand((UINT) time(&t));
- list *P = fillList(N), *Q = fillList(N), *R = new list();
- sumLists(R, P, Q);
- return 0 * _getch();
- }
- char random()
- {
- char r = rand() % (CHAR_MAX + 1 - CHAR_MIN) + CHAR_MIN;
- return r == 0 ? random() : r;
- };
- list *fillList(char index, list *next)
- {
- return index == 0 ? next : fillList(index - 1, new list(N - index, random(), next));
- }
- void sumLists(list *r, list *a, list *b)
- {
- if (a != NULL)
- {
- *r = *new list(a->n, a->a + b->a, new list());
- sumLists(r->next, a->next, b->next);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement