fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. template <typename typ>
  5. class stack{
  6. typ *tab;
  7. long wybrany, size;
  8. void powiekszSie();
  9. public:
  10. stack &operator=(const stack &o) = delete;
  11. stack(const stack &o) = delete;
  12. stack();
  13. ~stack(){delete []tab;}
  14. void push(typ &co);
  15. void pop() {wybrany --;}
  16. bool empty() {return wybrany == 0;}
  17. const typ top(){return tab[wybrany - 1];}
  18. };
  19. template <typename typ>
  20. stack<typ>::stack(){
  21. wybrany = 0;
  22. size = 0;
  23. tab = new typ[size];
  24. }
  25. template <typename typ>
  26. void stack<typ>::push(typ &co){
  27. if(wybrany == size)
  28. powiekszSie();
  29. tab[wybrany++] = co;
  30. }
  31. template <typename typ>
  32. void stack<typ>::powiekszSie(){
  33. typ *nowa = new typ[size + 10];
  34. for(int i=0;i<size;++i)
  35. nowa[i] = tab[i];
  36. delete []tab;
  37. tab = nowa;
  38. size += 10;
  39. }
  40.  
  41. int main(){
  42. int n;
  43. stack <int> mystack;
  44. cin>>n;
  45. for(int i=0, j; i<n; i++){
  46. cin>>j;
  47. mystack.push(j);
  48. }
  49. stack <int> mystack_np, mystack_p;
  50. while (!mystack.empty()){
  51. int x = mystack.top();
  52. mystack.pop();
  53. x%2 ? mystack_np.push(x) : mystack_p.push(x);
  54. }
  55. while (!mystack_np.empty()){
  56. cout<< mystack_np.top()<<" ";
  57. mystack_np.pop();
  58. }
  59. cout<<endl;
  60. while (!mystack_p.empty()){
  61. cout<< mystack_p.top()<<" ";
  62. mystack_p.pop();
  63. }
  64. return 0;
  65. }
  66.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
10
10 9 8 7 6 5 4 3 2 1
compilation info
prog.cpp:10: error: invalid pure specifier (only `= 0' is allowed) before ‘;’ token
prog.cpp:11: error: invalid pure specifier (only `= 0' is allowed) before ‘;’ token
prog.cpp: In instantiation of ‘stack<int>’:
prog.cpp:43:   instantiated from here
prog.cpp:10: error: initializer specified for non-virtual method ‘stack<typ>& stack<typ>::operator=(const stack<typ>&) [with typ = int]’
prog.cpp:11: error: initializer specified for non-virtual method ‘stack<typ>::stack(const stack<typ>&) [with typ = int]’
stdout
Standard output is empty