Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- //template <typename T>
- //void bubble(T *p, int n)
- //{
- // T temp;
- // for (int i = 0; i < n; i++)
- // {
- // for (int j = 0; j < n - i - 1; j++)
- // {
- // if (p[j] > p[j+1])
- // {
- // temp = p[j];
- // p[j] = p[j+1];
- // p[j+1] = temp;
- // }
- // }
- // }
- // return;
- //}
- //
- //template <typename T>
- //void ispis(T *p, int n)
- //{
- // for (int i = 0; i < n; i++)
- // {
- // cout << p[i] << " ";
- // }
- // cout << endl;
- // return;
- //}
- //
- //int main()
- //{
- // srand(time(NULL));
- // int *a = new int[3];
- // double *b = new double[5];
- // char *c = new char[4];
- //
- // for (int i = 0; i < 3; i++)
- // {
- // a[i] = rand() % 50;
- // }
- // for (int i = 0; i < 5; i++)
- // {
- // b[i] = (double)rand()/RAND_MAX * 10;
- // }
- // for (int i = 0; i < 4; i++)
- // {
- // c[i] = 65 + rand() % 25;
- // }
- //
- // bubble(a, 3);
- // bubble(b, 5);
- // bubble(c, 4);
- //
- // ispis(a, 3);
- // ispis(b, 5);
- // ispis(c, 4);
- //
- // delete[] a;
- // delete[] b;
- // delete[] c;
- // return 0;
- //}
- template <typename T>
- class stog
- {
- private:
- T *p;
- int n, size;
- public:
- stog(int x)
- {
- size = x;
- n = -1;
- p = new T[size];
- }
- stog(const stog& ref)
- {
- size = ref.size;
- p = new T[size];
- for (int i = 0; i < size; i++)
- {
- p[i] = ref.p[i];
- }
- }
- ~stog()
- {
- delete[] p;
- }
- stog& operator= (const stog& ref)
- {
- if (this != &ref)
- {
- size = ref.size;
- p = new T[size];
- for (int i = 0; i < size; i++)
- {
- p[i] = ref.p[i];
- }
- }
- return *this;
- }
- void push(T x)
- {
- if (n == size)
- {
- cout << "Puno." << endl;
- }
- else
- {
- p[++n] = x;
- }
- return;
- }
- T pop()
- {
- if (n < 0)
- {
- cout << "Prazno." << endl;
- }
- else
- {
- return p[n--];
- }
- }
- };
- int main()
- {
- stog<int> a(10);
- stog<double> b(20);
- a.push(5);
- a.push(3);
- cout << a.pop() << endl;
- cout << a.pop() << endl;
- b.push(3.4);
- b.push(17.1);
- b.push(-3.1);
- cout << b.pop() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement