Advertisement
Domerk

Пример очереди

Nov 25th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct elem
  5. {
  6.     int i;
  7.     elem*next;
  8. };
  9.  
  10. bool pop (elem*h, int&a);
  11. void push (elem*&h, int a);
  12.  
  13. int main ()
  14. {
  15.     int a=1;
  16.     elem* str1=0;
  17.     push (str1, a);
  18.     if (!pop(str1, a))
  19.         cout<<"Str is emty!";
  20.     std::cin.sync();
  21.     std::cin.clear();
  22.     std::cin.get();
  23.     return 0;
  24. }
  25.  
  26. bool pop (elem*h, int&a)
  27. {
  28.     if (h)
  29.     {
  30.         elem* tp = h -> next;
  31.         int t= h -> i;
  32.         delete h;
  33.         h=tp;
  34.         return t;
  35.     }
  36.     return false;
  37. }
  38.  
  39. void push (elem*&h, int a)
  40. {
  41.     elem*p=new elem;
  42.     p->i=a;
  43.     p->next=h;
  44.     h=p;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement