Advertisement
p0lich

(stack)task_1(uncompleted)

May 5th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. # include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct stack
  6. {
  7. int inf;
  8. stack*next;
  9. };
  10.  
  11. stack*init()
  12. {
  13. return NULL;
  14. };
  15.  
  16. void push(stack*&h, int x)
  17. {
  18. stack*r=new stack;
  19. r->inf=x;
  20. r->next=h;
  21. h=r;
  22. }
  23.  
  24. int top (stack*h)
  25. {
  26. return h->inf;
  27. }
  28.  
  29. int pop(stack*&h)
  30. {
  31. int i=h->inf;
  32. stack*r=h;
  33. h=h->next;
  34. delete r;
  35. return i;
  36. }
  37.  
  38. int main()
  39. {
  40. int n;
  41. cin >> n;
  42. int prime;
  43. cin >> prime;
  44. stack*rad = NULL;
  45. int*s=new int[n];
  46. for (int i=0;i<n;i++)
  47. {
  48. cin >> s[i];
  49. push(rad,s[i]);
  50. }
  51. for (int i=0;i<n;i++)
  52. cout<<s[i]<<" ";
  53. cout<<endl;
  54. int i=n-1;
  55. while(rad)
  56. {
  57. if (s[i]==prime)
  58. pop(rad);
  59. else
  60. cout << pop(rad) << " ";
  61. i--;
  62. }
  63. cout << endl;
  64. system("pause");
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement