Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// purva grupa
- #include<iostream>
- #include<cstring>
- using namespace std;
- struct Element
- {
- int x;
- Element* next;
- };
- class Stack
- {
- Element* start;
- public:
- Stack()
- {
- start=NULL;
- }
- int top()
- {
- return (start->x);
- }
- void push(int a)
- {
- Element* k=start;
- start= new Element;
- start->x=a;
- start->next=k;
- }
- int pop()
- {
- int a=start->x;
- Element*p=start;
- start=p->next;
- delete[]p;
- return a;
- }
- bool isempty()
- {
- return start==NULL;
- }
- void print()
- {
- while(!isempty())
- {
- cout<<pop()<<" ";
- }
- }
- Stack operator=(Stack a)
- {
- Stack temp=Stack();
- Stack c=Stack();
- while(!a.isempty())
- {
- temp.push(a.pop());
- }
- while(!temp.isempty())
- {
- c.push(temp.top());
- c.push(temp.top());
- temp.pop();
- }
- ///return *this;
- return c;
- }
- };
- Stack Merge(Stack a, Stack b)
- {
- Stack temp=Stack();
- while(!a.isempty())
- {
- temp.push(a.pop());
- }
- while(!b.isempty())
- {
- temp.push(b.pop());
- }
- return temp;
- }
- int minStack(Stack a)
- {
- int flag=0;
- Stack tempstack=Stack();
- while(!a.isempty())
- {
- flag++;
- tempstack.push(a.pop());
- }
- int temp[flag];
- int j=0;
- while(!tempstack.isempty())
- {
- temp[j]=tempstack.pop();
- j++;
- }
- int minn=temp[0];
- for(int i=0; i<flag; i++)
- {
- if(minn>temp[i]) minn=temp[i];
- }
- return minn;
- }
- int main()
- {
- Stack a=Stack();
- a.push(1);
- a.push(2);
- a.push(3);
- a.push(4);
- Stack b=Stack();
- b.push(5);
- b.push(6);
- b.push(7);
- b.push(8);
- Merge(a,b).print();
- Stack c=Stack();
- c.push(4);
- c.push(7);
- c.push(9);
- c.push(15);
- cout<<endl<<"min = "<<minStack(c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement