Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct tlist
- {
- int inf;
- tlist *a;
- };
- void addstack(tlist **sp, int inf)
- {
- tlist *spt = new tlist;
- spt->inf = inf;
- spt->a = sp;
- }
- void delstack(tlist **sp)
- {
- tlist *spt;
- //int inf;
- while (sp != NULL)
- {
- spt = sp;
- //inf = ;
- cout << sp->inf << endl;
- sp = sp->a;
- delete spt;
- }
- system("pause");
- }
- void readstack(tlist *sp)
- {
- while (sp)
- {
- cout << sp->inf << " ";
- sp = sp->a;
- }
- cout << endl;
- system("pause");
- }
- int main()
- {
- tlist *sp;
- sp = NULL;
- int n, k;
- cout << "VVEDI CHISLO ELEMENTOV V STEKE: ";
- cin >> n;
- if (n < 1) return 0;
- for (int i = 0; i < n; i++)
- {
- cout << "VVEDI CHISLO: ";
- cin >> k;
- addstack(&sp, k);
- }
- cout << "VVEDYNIY STEK: ";
- readstack(sp);
- tlist *p, *t;
- //p = sp;
- //t = NULL;
- tlist*tmp = new tlist;
- tmp->a = sp;
- while (tmp!=NULL&&tmp->a != NULL) {
- if (tmp->a->inf % 2 == 0) {
- t=tmp->a
- tmp->a = tmp->a->a;
- delete t;
- }
- }
- /*while (p)
- {
- if (p->inf % 2 == 0)
- {
- if (p == sp)
- {
- sp = sp->a;
- delete p;
- p = sp;
- }
- else
- {
- t->a = p->a;
- delete p;
- p = t->a;
- }
- }
- else
- {
- t = p;
- p = p->a;
- }
- }*/
- cout << "NOVIY STACK: ";
- readstack(sp);
- delstack(&sp);
- return 0;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement