Created
May 4, 2016 02:57
-
-
Save wbadart/3529bfb1a9cc8927f7066430e132f4a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
template<typename T> | |
class container{ | |
public: | |
container(); | |
T* begin(); | |
T* end(); | |
void push_back(T); | |
private: | |
T* head; | |
T* tail; | |
int len; | |
}; | |
using namespace std; | |
template<typename T> | |
container<T>::container():len(0){ | |
head = new T; | |
} | |
template<typename T> | |
T* container<T>::begin(){ | |
return head; | |
} | |
template<typename T> | |
T* container<T>::end(){ | |
return (head + len); | |
} | |
template<typename T> | |
void container<T>::push_back(T d){ | |
*(head + len++) = d; | |
tail++; | |
} | |
int main(void){ | |
container<int> a; | |
a.push_back(5); | |
a.push_back(10); | |
for(auto i: a){ | |
cout << i << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment