Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- using namespace std;
- struct stack
- {
- int inf;
- stack*next;
- };
- stack*init()
- {
- return NULL;
- };
- void push(stack*&h, int x)
- {
- stack*r=new stack;
- r->inf=x;
- r->next=h;
- h=r;
- }
- int top (stack*h)
- {
- return h->inf;
- }
- int pop(stack*&h)
- {
- int i=h->inf;
- stack*r=h;
- h=h->next;
- delete r;
- return i;
- }
- int main()
- {
- int n;
- cin >> n;
- int prime;
- cin >> prime;
- stack*rad = NULL;
- int*s=new int[n];
- for (int i=0;i<n;i++)
- {
- cin >> s[i];
- push(rad,s[i]);
- }
- for (int i=0;i<n;i++)
- cout<<s[i]<<" ";
- cout<<endl;
- int i=n-1;
- while(rad)
- {
- if (s[i]==prime)
- pop(rad);
- else
- cout << pop(rad) << " ";
- i--;
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement