Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. template <class T>
  8.  
  9. class Stos {
  10.  
  11. public:
  12. int size;
  13. T *stos;
  14. int ptr;
  15.  
  16. Stos() {
  17.  
  18. size = 10;
  19. stos = new T[size];
  20. ptr = 0;
  21. }
  22.  
  23. ~Stos() {
  24.  
  25. }
  26.  
  27. void push(T x) {
  28.  
  29. stos[ptr] = x;
  30. ptr++;
  31. }
  32.  
  33. T* pop(void) {
  34.  
  35. ptr--;
  36. return stos + ptr;
  37. }
  38. };
  39.  
  40. int main(void) {
  41.  
  42. Stos <string> s1;
  43.  
  44. s1.push("Oto");
  45. s1.push("jest");
  46. s1.push("stos.");
  47.  
  48. cout<< endl;
  49. cout << *s1.pop() << " " << *s1.pop() << " " << *s1.pop() << endl << endl;
  50.  
  51. system("pause");
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement