Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <algorithm>
- using namespace std;
- class Integers {
- public:
- int *niz = new int[100];
- int *length = new int;
- Integers()
- {
- *length = 0;
- }
- Integers(Integers &p, int len)
- {
- *length = 0;
- for (int i = 0; i < len; i++)
- {
- //cout << "len: " << len << endl;
- //cout << niz[*length] << endl;
- niz[*length] = p.niz[i];
- *length += 1;
- }
- }
- int GetLength()
- {
- return *length;
- }
- void Add(int num)
- {
- niz[*length] = num;
- *length += 1;
- }
- void Remove()
- {
- niz[*length] = NULL;
- *length -= 1;
- }
- void Print()
- {
- for (int i = 0; i < *length; i++)
- {
- cout << niz[i] << " ";
- }
- cout << endl;
- }
- void PrintSorted(Integers n1)
- {
- sort(&n1.niz[0], &n1.niz[*length]);
- for (int i = 0; i < *length; i++)
- {
- cout << n1.niz[i] << " ";
- }
- cout << endl;
- }
- };
- int main()
- {
- Integers s1;
- s1.Add(10);
- s1.Add(30);
- s1.Add(25);
- s1.Add(5);
- //s2 = s1;
- Integers s2(s1, s1.GetLength());
- s2.Add(50);
- s2.Add(1);
- s1.Print();
- s2.Print();
- cout << "s1 sorted:";
- s1.PrintSorted(s1);
- cout << "s2 sorted:";
- s2.PrintSorted(s2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement