Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. template <typename T>
  8. class List
  9. {
  10.     T * Elemente;
  11.     int Count, Allocated;
  12. public:
  13.  
  14.     List<T>()
  15.     {
  16.         Count = 0;
  17.         Allocated = 0;
  18.         Elemente = NULL;
  19.     }
  20.  
  21.     ~List<T>()
  22.     {
  23.         delete[] Elemente;
  24.     }
  25.  
  26.     bool Add(const T &element)
  27.     {
  28.  
  29.             T *aux = new(std::nothrow) T[Allocated + 1];
  30.             for (int i = 0; i < Allocated; i++)
  31.             {
  32.                 aux[i] = Elemente[i];
  33.             }
  34.             aux[Allocated] = element;
  35.             delete[] Elemente;
  36.             Elemente = aux;
  37.             Count++;
  38.             Allocated++;
  39.             return true;
  40.        
  41.  
  42.     }
  43.     T&   operator[] (int index)
  44.     {
  45.         /*if (index >= Count) return NULL;
  46.         if (index < 0)      return NULL;
  47.         */
  48.         return Elemente[index];
  49.  
  50.     }
  51.  
  52.     void Sort()
  53.     {
  54.         for (int i = 0; i < Count; i++)
  55.         {
  56.             for (int j = i+1; j < Count; j++)
  57.             {
  58.                 if (Elemente[i] > Elemente[j])
  59.                 {
  60.                     swap(Elemente[i], Elemente[j]);
  61.                 }
  62.             }
  63.         }
  64.     }
  65.     void Print()
  66.     {
  67.         for (int i = 0; i < Count; i++)
  68.         {
  69.             cout << Elemente[i] << " ";
  70.         }
  71.     }
  72.  
  73. };
  74.  
  75. int main()
  76. {
  77.     string r = "2  5";
  78.     List<string> x;
  79.  
  80.     for (int i = 0; i < 200; i++)
  81.     {
  82.         x.Add(r);
  83.         std::cout<<x[i]<<" ";
  84.     }
  85.  
  86.     //std::cout
  87.     ///x.Print();
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement