fork(2) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int rozmiar;
  6.  
  7. void push(short* liczba,short* wsk)
  8. {
  9. *wsk=*liczba;
  10. }
  11.  
  12. void pop(short* wsk)
  13. {
  14. cout<<*wsk<<"\n";
  15. }
  16.  
  17. void size(short* ogon,short* glowa)
  18. {
  19. rozmiar=ogon-glowa;
  20. cout<<rozmiar<<"\n";
  21. }
  22.  
  23. int main()
  24. {
  25. int test;
  26. cin>>test;
  27.  
  28. short* tablica=new short [test];
  29. short* glowa=tablica;
  30.  
  31. for(int i=0;i<test;i++)
  32. {
  33. char znak;
  34. short liczba;
  35.  
  36. cin>>znak;
  37. switch(znak)
  38. {
  39. case '+':
  40. cin>>liczba;
  41. push(&liczba,tablica);
  42. tablica++;
  43. break;
  44. case '-':
  45. pop(glowa);
  46. glowa++;
  47. break;
  48. case '?':
  49. size(tablica,glowa);
  50. break;
  51. }
  52. }
  53. delete [] tablica;
  54. return 0;
  55. }
  56.  
Runtime error #stdin #stdout #stderr 0.01s 5504KB
stdin
8
+ 170
+ 190
-
+ 200
+ 200
?
-
?
stdout
170
3
190
stderr
munmap_chunk(): invalid pointer