fork(5) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct queue{
  6. int storage[100000];
  7. int start;
  8. int finish;
  9. queue(){
  10. start = 0;
  11. finish = 0;
  12. }
  13.  
  14. void push(int n){
  15. storage[finish] = n;
  16. finish++;
  17. }
  18.  
  19. int pop(){
  20. int a = storage[start];
  21. start++;
  22. return a;
  23. }
  24.  
  25. int front(){
  26. return storage[start];
  27. }
  28.  
  29. int size(){
  30. return finish - start;
  31. }
  32.  
  33. string clear(){
  34. finish = 0;
  35. start = 0;
  36. return "ok";
  37. }
  38.  
  39. string exit(){
  40. return "bye";
  41. }
  42. };
  43.  
  44. int main() {
  45. string a;
  46. queue x;
  47. while(cin >> a){
  48. if(a == "push"){
  49. int n;
  50. cin >> n;
  51. x.push(n);
  52. cout << "ok" << endl;
  53. }
  54. if(a == "pop"){
  55. cout << x.pop() << endl;
  56. }
  57. if(a == "front"){
  58. cout << x.front() << endl;
  59. }
  60. if(a == "size"){
  61. cout << x.size() << endl;
  62. }
  63. if(a == "clear"){
  64. cout << x.clear() << endl;
  65. }
  66. if(a == "exit"){
  67. cout << x.exit() << endl;
  68. return 0;
  69. }
  70. }
  71. return 0;
  72. }
Success #stdin #stdout 0s 3732KB
stdin
push 123
size
push -5 
pop
exit
stdout
ok
1
ok
123
bye