Advertisement
dumitreskw

Untitled

Feb 14th, 2019
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. #define dim 1001
  5. struct Stiva
  6. {
  7. int st[dim];
  8. int top;
  9. int Empty()
  10. {
  11. return top == -1;
  12. }
  13. int Full()
  14. {
  15. return top == dim-1;
  16. }
  17. void Init()
  18. {
  19. top = -1;
  20. }
  21. void Push(int x)
  22. {
  23. if (!Full())
  24. st[++top]=x;
  25. }
  26. void Pop()
  27. {
  28. if (!Empty()) top--;
  29. }
  30. int Front()
  31. {
  32. return st[top];
  33. }
  34. };
  35. int main()
  36. {
  37. int n;
  38. Stiva s;
  39. cout<<"n= ";
  40. cin>>n;
  41. s.Init();
  42. while(n>0)
  43. {
  44. s.Push(n%2);
  45. n/=2;
  46. }
  47. while(!s.Empty())
  48. {
  49. cout<<s.Front();
  50. s.Pop();
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement