fork download
  1. #include<iostream>
  2. using namespace std;
  3. class Stack{
  4. private:
  5. int top;
  6. int capacity;
  7. string *arr;
  8. public:
  9. Stack(int n){
  10. top=-1;
  11. capacity=n;
  12. arr=(string *)malloc(capacity*sizeof(string));
  13. }
  14. bool isempty()
  15. {
  16. if(top==-1)
  17. {
  18. cout<<"ig"<<endl;
  19. return true;
  20. }
  21. else return false;
  22. }
  23. string push(Stack *s,string a)
  24. {
  25.  
  26. s->top++;
  27. //cout<<s->top;
  28. s->arr[s->top]=a;
  29. cout<<"Successfully pushed"<<endl;
  30. return arr[s->top];
  31.  
  32. }
  33. string pop(Stack *s)
  34. {
  35. if(isempty())
  36. {
  37. return "Ignored";
  38. }
  39. else{
  40. string b=s->arr[s->top];
  41. s->top--;
  42. return b;
  43. }
  44. }
  45. string printtop()
  46. {
  47. if(top==-1)
  48. {
  49. return "IGNORED";
  50. }
  51. else{
  52. string a=arr[top];
  53. return a;
  54. }
  55. }
  56. int gettop()
  57. {
  58. return top;
  59. }
  60. void print()
  61. {
  62. for(int i=top;i>=0;i--)
  63. {
  64. cout<<arr[i]<<endl;
  65. }
  66. }
  67. };
  68.  
  69. int main()
  70. {
  71. int n;
  72. cin>>n;
  73. Stack b(10),f(10);
  74. string r="http://w...content-available-to-author-only...j.com/";
  75. b.push(&b,r);
  76.  
  77. for(int i=0;i<100;i++)
  78. {
  79. string command, url;
  80. cin>>command;
  81. if(command=="VISIT")
  82. {
  83. cin>>url;
  84. if(f.isempty()){
  85. string p=b.push(&b,url);
  86. }
  87. else{
  88. string a=f.pop(&f);
  89. b.push(&b,a);
  90. string p=b.push(&b,url);
  91. int j=f.gettop();
  92. for(int i=j;i>=0;i--)
  93. {
  94. string q=f.pop(&f);
  95. }
  96. cout<<j<<endl;
  97. //cout<<p<<endl;
  98. }
  99.  
  100. }
  101. else if(command=="BACK"){
  102. string a=b.pop(&b);
  103. string c=f.push(&f,a);
  104. cout<<b.printtop()<<endl;
  105. //cout<<"*****BACKWARD STACK******"<<endl;
  106. //b.print();
  107. }else if(command=="FORWARD"){
  108. string a=f.pop(&f);
  109. string d=b.push(&b,a);
  110. string c=f.printtop();
  111. cout<<c<<endl;
  112. //cout<<"*****FORWARD STACK******"<<endl;
  113. //f.print();
  114. }else if(command=="QUIT"){
  115. break;
  116. }
  117. }
  118. cout<<"Completed"<<endl;
  119. }
  120.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Successfully pushed
Completed