Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <time.h>
- using namespace std;
- struct tstk {
- int inf;
- tstk *a;
- }*a, *b;
- tstk *AddStask(tstk *sp, int inf) {
- tstk *spt = new tstk;
- spt->inf = inf;
- spt->a = sp;
- return spt;
- }
- tstk *ReadStackD(tstk *sp, int &inf) {
- if (sp == NULL) return NULL;
- tstk *spt = sp;
- inf = sp->inf;
- sp = sp->a;
- delete spt;
- return sp;
- }
- tstk *DelStackAll(tstk *sp) {
- tstk *spt; int inf;
- while (sp != NULL) {
- spt = sp;
- inf = sp->inf;
- sp = sp->a;
- delete spt;
- }
- return NULL;
- }
- int main()
- {
- srand(time(NULL));
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- int t = rand() % 101 - 50;
- cout << t << " ";
- a = AddStask(a, t);
- }
- cout << endl;
- int t;
- while (a != NULL) {
- a = ReadStackD(a, t);
- b = AddStask(b, t);
- }
- b = ReadStackD(b, t);
- while (b != NULL) {
- b = ReadStackD(b, t);
- a = AddStask(a, t);
- }
- while (a != NULL) {
- a = ReadStackD(a, t);
- cout << t << " ";
- }
- DelStackAll(a);
- DelStackAll(b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement