Posted By

tojakopec on 11/15/10


Tagged

sp foi vz


Versions (?)

Zadatak 2 - stog_pokazivac.h


 / Published in: C++
 

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

Report this snippet  

You need to login to post a comment.