include iostream using namespace std struct tstk int inf tstk tstk Add

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std;
struct tstk
{
int inf;
tstk *a;
};
tstk *AddStack(tstk *, int);
tstk *DelStackAll(tstk *);
int main()
{
tstk *st1, *st2, *i;
int n, x;
st1 = st2 = NULL;
cout << "Vvedite kolithestvo elementov:";
cin >> n;
for ( int j=0; j<n; j++ )
{
cin >> x;
st1 = AddStack( st1, x );
}
for ( i = st1; i!=NULL; i = i->a )
if ( i-> inf>0 )
st2 = AddStack( st2, i->inf );
cout << "stack1" << endl;
DelStackAll( st1 );
cout << "stack2" << endl;
DelStackAll( st2 );
return 0;
}
tstk *AddStack( tstk *sp, int inf )
{
tstk *spt = new tstk;
spt-> inf = inf;
spt-> a = sp;
return spt;
}
tstk *DelStackAll(tstk *sp)
{
tstk *spt; int inf;
while(sp != NULL) {
spt = sp;
inf= sp-> inf;
cout << inf << endl;
sp = sp->a;
delete spt; }
return NULL;
}