Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct list {
- int elem;
- list* next;
- };
- void run(list* p) {
- cout <<"List:";
- while (p->next != nullptr) {
- cout << " " << p->elem;
- p = p->next;
- }
- cout << endl;
- }
- void Fill_List(list*p) {
- setlocale(LC_ALL, "RUS");
- int size;
- cout << "Введите количество элементов списка" << endl;
- cin >> size;
- cout << "Вводите элементы" << endl;
- for (int i = 0; i < size; i++) {
- cin >> p->elem;
- p->next = new list;
- p = p->next;
- }
- p->next = nullptr;
- }
- void input_after(list* p) {
- while (p->next != nullptr) {
- if (p->elem % 2 == 0) {
- list* tmpR = new list;
- tmpR->elem = pow(p->elem, 2);
- tmpR->next = p->next;
- p->next = tmpR;
- p = tmpR;
- }
- p = p->next;
- }
- }
- void input_before(list*p) {
- if (p->elem % 2 == 0) {
- list*r = new list;
- r->elem = pow(p->elem, 2);
- r->next = p;
- p = r;
- }
- while (p->next != nullptr) {
- if (p->next->elem % 2 == 0) {
- list*r = new list;
- r->elem = p->next->elem * p->next->elem;
- r->next = p->next;
- p->next = r;
- p = r;
- }
- p = p->next;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- list* begin = new list;
- list*p = begin;
- Fill_List(begin);
- input_before(begin);
- run(begin);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement