Zadatak 2. - stog_polje.h


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include<iostream>
  2.  
  3. #define n 50
  4.  
  5. using namespace std;
  6.  
  7. //int kursor=n-1;
  8. struct elementtype
  9. {
  10. int sbroj;
  11. char proiz[20];
  12. char model[20];
  13. int godina;
  14.  
  15. };
  16.  
  17. struct stack {
  18. elementtype st[n];
  19. int cursor;
  20. };
  21.  
  22. void Init(stack *S)
  23. {
  24. S->cursor = n - 1;
  25. }
  26.  
  27.  
  28. bool IsEmpty(stack *S)
  29. {
  30. if(S->cursor >= n - 1)
  31. {
  32. return true;
  33. }
  34. else
  35. {
  36. return false;
  37. }
  38. }
  39.  
  40.  
  41. void Push(elementtype x, stack *S){
  42. if(S->cursor == 0)
  43. cout << "Stog je pun" << endl;
  44. else
  45. {
  46. S->cursor--;
  47. S->st[S->cursor] = x;
  48. }
  49. };
  50.  
  51. elementtype Top(stack *S)
  52. {
  53. if(IsEmpty(S))
  54. cout << "Nema zapisa\n";
  55. else
  56. return S->st[S->cursor];
  57. }
  58. void Pop(stack *S){
  59. if(IsEmpty(S))
  60. cout << "\nNema zapisa!\n";
  61. else
  62. {
  63. S->cursor++;
  64. //cout<<"\n\nUnos izbrisan!\n";
  65. }//else
  66. }//Pop

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.