Program automobil stog_pokazivac.h


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



Copy this code and paste it in your HTML
  1. #include <iostream>
  2.  
  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 list {
  12. elementtype element;
  13. list *next;
  14. };
  15. struct stack
  16. {
  17. list st;
  18. list *top;
  19. };
  20. void Init(stack *S)
  21. {
  22. S->top = NULL;
  23. S->st.next = NULL;
  24. }
  25. void Push(elementtype x, stack *S)
  26. {
  27. list *newElement = new list;
  28.  
  29. newElement->next = S->top;
  30. newElement->element = x;
  31. S->top = newElement;
  32. }
  33. elementtype Top(stack *S)
  34. {
  35. return S->top->element;
  36. }
  37.  
  38. bool IsEmpty(stack *S)
  39. {
  40. if(S->top == NULL)
  41. {
  42. return true;
  43. }
  44. else
  45. {
  46. return false;
  47. }
  48. }
  49. void Pop(stack *S)
  50. {
  51. if(IsEmpty(S))
  52. {
  53. cout << "Stog je prazan." << endl;
  54. }
  55. else
  56. {
  57. delete S->top;
  58. S->top = S->top->next;
  59. }
  60. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.