Advertisement
Dambosin

wwwwwwwww

Mar 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 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;
  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.         cout<<inf<<" ";
  32.         sp = sp->a;
  33.         delete spt;
  34.     }
  35.     return NULL;
  36. }
  37. int main()
  38. {  
  39.     srand(time(NULL));
  40.     int n;
  41.     cin >> n;
  42.     for (int i = 0; i < n; i++) {
  43.         int t = rand() % 101 - 50;
  44.         cout << t << " ";
  45.         a = AddStask(a, t);
  46.     }
  47.     cout << endl;
  48.     tstk r = a;
  49.     a=a->a;
  50.     delete r;
  51.     DelStackAll(a);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement