Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <string>
- using namespace std;
- template <typename T>
- class List
- {
- T * Elemente;
- int Count, Allocated;
- public:
- List<T>()
- {
- Count = 0;
- Allocated = 0;
- Elemente = NULL;
- }
- ~List<T>()
- {
- delete[] Elemente;
- }
- bool Add(const T &element)
- {
- T *aux = new(std::nothrow) T[Allocated + 1];
- for (int i = 0; i < Allocated; i++)
- {
- aux[i] = Elemente[i];
- }
- aux[Allocated] = element;
- delete[] Elemente;
- Elemente = aux;
- Count++;
- Allocated++;
- return true;
- }
- T& operator[] (int index)
- {
- /*if (index >= Count) return NULL;
- if (index < 0) return NULL;
- */
- return Elemente[index];
- }
- void Sort()
- {
- for (int i = 0; i < Count; i++)
- {
- for (int j = i+1; j < Count; j++)
- {
- if (Elemente[i] > Elemente[j])
- {
- swap(Elemente[i], Elemente[j]);
- }
- }
- }
- }
- void Print()
- {
- for (int i = 0; i < Count; i++)
- {
- cout << Elemente[i] << " ";
- }
- }
- };
- int main()
- {
- string r = "2 5";
- List<string> x;
- for (int i = 0; i < 200; i++)
- {
- x.Add(r);
- std::cout<<x[i]<<" ";
- }
- //std::cout
- ///x.Print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement