Posted By

ivamilice on 11/15/10


Tagged

stog


Versions (?)

Implementacija stoga pomoću polja


 / Published in: C++
 

  1. #include<iostream>
  2. using namespace std;
  3. struct auto{
  4. int serial, godina;
  5. char proizvodac[50], model[50];
  6. };
  7. typedef auto element;
  8. struct el{
  9. element value;
  10. struct el *next;
  11. };
  12. typedef struct el stog;
  13. element TopS(stog *s){
  14. stog *top;
  15. if(s->next==NULL){
  16. cout<<" Greska! "<<endl;
  17. exit(1);
  18. };
  19. top=s->next;
  20. return top->value;
  21. };
  22. void PushS(element z, stog *s){
  23. stog *novi;
  24. novi=(stog *)malloc(sizeof(stog));
  25. novi->value=z;
  26. novi->next=s->next;
  27. s->next=novi;
  28. };
  29. void PopS(stog *s){
  30. stog *temp;
  31. if(s->next==NULL){
  32. cout<<" Greska! "<<endl;
  33. exit(1);
  34. };
  35. temp=s->next;
  36. s->next=temp->next;
  37. free(temp);
  38. };
  39. stog * InitS(void){
  40. stog *s;
  41. s=(stog *)malloc(sizeof(stog));
  42. s->next=NULL;
  43. return s;
  44. };
  45. int IsEmptyS(stog *s){
  46. if(s->next==NULL) return 1;
  47. else return 0;
  48. };

Report this snippet  

You need to login to post a comment.