Advertisement
Dambosin

qqqqqqqqq

Mar 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <time.h>
  4. using namespace std;
  5. struct tstk {
  6.     int inf;
  7.     tstk *a;
  8. }*a, *b;
  9.  
  10. tstk *AddStask(tstk  *sp, int inf) {
  11.     tstk *spt = new tstk;
  12.     spt->inf = inf;
  13.     spt->a = sp;
  14.     return spt;
  15. }
  16.  
  17. tstk *ReadStackD(tstk *sp, int &inf) {
  18.     if (sp == NULL) return NULL;
  19.     tstk *spt = sp;
  20.     inf = sp->inf;
  21.     sp = sp->a;
  22.     delete spt;
  23.     return sp;
  24. }
  25.  
  26. tstk *DelStackAll(tstk *sp) {
  27.     tstk *spt; int inf;
  28.     while (sp != NULL) {
  29.         spt = sp;
  30.         inf = sp->inf;
  31.         sp = sp->a;
  32.         delete spt;
  33.     }
  34.     return NULL;
  35. }
  36. int main()
  37. {  
  38.     srand(time(NULL));
  39.     int n;
  40.     cin >> n;
  41.     for (int i = 0; i < n; i++) {
  42.         int t = rand() % 101 - 50;
  43.         cout << t << " ";
  44.         a = AddStask(a, t);
  45.     }
  46.     cout << endl;
  47.     int t;
  48.     while (a != NULL) {
  49.        
  50.         a = ReadStackD(a, t);
  51.         b = AddStask(b, t);
  52.     }
  53.     b = ReadStackD(b, t);
  54.     while (b != NULL) {
  55.         b = ReadStackD(b, t);
  56.         a = AddStask(a, t);
  57.     }
  58.     while (a != NULL) {
  59.         a = ReadStackD(a, t);
  60.         cout << t << " ";
  61.     }
  62.     DelStackAll(a);
  63.     DelStackAll(b);
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement