Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. #define MAX 10
  5.  
  6. struct Stack{
  7. int array[MAX];
  8. int top;
  9. void init();
  10. bool isFull();
  11. bool isEmpty();
  12. void push(int e);
  13. int pop(int br);
  14. int peek(int p);
  15. };
  16.  
  17. void Stack::init()
  18. {
  19. top=-1;
  20. }
  21. bool Stack::isEmpty()
  22. {
  23. return (top==-1);
  24. }
  25. bool Stack::isFull()
  26. {
  27. return(top==MAX-1);
  28. }
  29.  
  30. void Stack::push(int br)
  31. {
  32. if(isFull())
  33. {
  34. cout<<"Magacinot e poln"<<endl;
  35. }
  36. else
  37. {
  38. array[++top]=br;
  39. }
  40. }
  41.  
  42. int Stack::pop(int br)
  43. {
  44. if(!isEmpty())
  45. {
  46. return (array[top--]) ;
  47. }
  48. else{
  49. cout<<"Magacinot e prazen"<<endl;
  50. }
  51. }
  52. int Stack::peek(int p)
  53. {
  54. return array[top];
  55. }
  56.  
  57. int najdiPozicija(Stack magacin, int broj)
  58. {
  59. int i=0;
  60. while(!magacin.isEmpty)
  61. {
  62. if(magacin.peek==broj)
  63. {
  64. i=MAX-magacin.top-1;
  65. }
  66. }
  67. return i;
  68. }
  69.  
  70. int main()
  71. {
  72. Stack magacin;
  73. int broj;
  74. magacin.init();
  75. for (int i = 0; i < 10; i++)
  76. {
  77. cin >> broj;
  78. magacin.push(broj);
  79. }
  80. cin >> broj;
  81. int pozicija = najdiPozicija(magacin, broj);
  82. void izbrishi(Stack magacin, int i);
  83. cout<<pozicija<<endl;
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement