Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<iostream>
- using namespace std;
- struct stack
- {
- int inf;
- stack* a;
- };
- stack* Create(stack*&sp);
- stack* Add(stack*&sp,int inf);
- void Find(stack*&);
- //void Execusion(stack*&);
- void Delete(stack *&, stack *&);
- int menu();
- void Read(stack *);
- int main()
- {
- stack *sp=new stack;
- stack*now;
- now = NULL;
- sp=NULL;
- while(true)
- {
- switch (menu())
- {
- case 1:sp=Create(sp);
- case 2: Find(sp);
- case 3: Read(sp);
- }
- }
- }
- int menu()
- {
- int i;
- cin>>i;
- return i;
- }
- stack* Create(stack*&sp)
- {
- stack*yub;
- int n, j;
- cout << "skolko znachenii vnesti v stek?" << endl;
- cin >> n;
- for (int i = 0;i < n;i++)
- {
- cout << "vvedite" << i << "ellement" << endl;
- cin >> j;
- yub=Add(sp, j);
- }
- return yub;
- }
- stack* Add(stack*&sp,int inf)
- {
- stack* spt = new stack;
- spt->a = sp;
- spt->inf = inf;
- sp = spt;
- return spt;
- }
- void Find(stack*&sp)
- {
- stack *temp1 = new stack;
- temp1=sp;
- stack *temp2 = new stack;
- temp2=sp;
- stack *temp3 = new stack;
- temp3=sp;
- while(temp1->inf > 0 && temp1->a!=NULL)
- {
- temp1 = temp1->a;
- }
- if(temp1>0&&temp1->a==NULL){cout<<"There is no negative elements in stack"<<endl;return;}
- temp3=NULL;
- temp2=temp1->a;
- while(temp2 != NULL)
- {
- if(temp2->inf<0){temp3=temp2;};
- temp2 = temp2->a;
- }
- if(temp3==NULL) { cout<<" There is no 2 negative elements in stack"; return;}
- Delete (temp1,temp3);
- }
- void Delete(stack *&temp1, stack *&temp3)
- {
- stack *remove = new stack;
- stack *y = new stack;
- stack *z = new stack;
- y=temp1;
- y=y->a;
- temp1->a=temp3;
- while(y!=temp3)
- {
- z=y->a;
- remove = y;
- delete remove;
- y = z;
- }
- }
- void Read(stack *spt)
- {
- while(spt !=NULL)
- {
- cout<<spt->inf<<"\t";
- spt=spt->a;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement