Program automobil stog_polje.h


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



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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.