Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<string>
- #include<algorithm>
- #include<random>
- using namespace std;
- random_device r;
- class L {
- L* p = nullptr;
- int inf;
- public:
- L(int q) {
- inf = q;
- }
- L* soz(int );
- double sr();
- void zm(int , int );
- void men();
- void vuv() {
- cout << this->inf << ' ';
- L* w = this->p;
- while (w != nullptr) {
- cout << w->inf << ' ';
- w = w->p;
- }
- cout << '\n';
- }
- };
- int main() {
- L*u(0);
- u = u->soz(5);
- u->vuv();
- u->zm(4,0);
- u->vuv();
- u->men();
- u->vuv();
- system("pause");
- }
- L* L::soz(int n) {
- L* o = new L(r() % 5);
- L* q = o;
- for (int i = 1; i < n; ++i) {
- L* v = new L(r() % 5);
- o->p = v;
- o = v;
- }
- return q;
- }
- double L:: sr() {
- int s = this->inf;
- int k = 1;
- L* w = this->p;
- while (w != nullptr) {
- s += w->inf;
- ++k;
- w = w->p;
- }
- return s * 1.0 / k;
- }
- void L:: zm(int x, int y) {
- if (this->inf == x) {
- this->inf = y;
- }
- L* w = this->p;
- while (w != nullptr) {
- if (w->inf == x) {
- w->inf = y;
- }
- w = w->p;
- }
- }
- void L:: men() {
- L* u = this;
- L* w = this->p;
- if (w != nullptr) {
- while (w->p != nullptr) {
- w = w->p;
- }
- swap(u->inf, w->inf);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment