Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int N;
  7. int *tab;
  8. int q=0;
  9. int p=0;
  10.  
  11.  
  12.  
  13. bool isEmpty()
  14. {
  15. return(p==(-1));
  16. }
  17.  
  18. bool isFull()
  19. {
  20. return(p==N);
  21. }
  22.  
  23. void push(int a)
  24. {
  25. if(!isFull()){
  26.     for(int i=N-1;i>=0;i--){
  27.         tab[i]=tab[i-1];
  28.     }
  29.     tab[0]=a;
  30.  p=p+1;
  31.  
  32. }
  33.  else
  34.  {
  35.  cout<<"Stos pelny\t"<<endl;
  36.  }
  37. }
  38.  
  39. void print()
  40. {
  41.  if(isEmpty())
  42.  {
  43.   cout << "Pusty stos\n";
  44.   return;
  45.  }
  46. for (int i = 0; i<p; i++)
  47. {
  48. cout << tab[i] <<"\t";
  49. }
  50. cout << endl;
  51. }
  52.  
  53.  
  54. int main()
  55. {
  56. tab = new int[N];
  57. N=5;
  58. for(int i=0;i<5;i++){
  59.     tab[i]=0;
  60. }
  61.  
  62. push(2);
  63. push(3);
  64. push(4);
  65. push(1);
  66.  
  67.  
  68. print();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement