Posted By

mlcorak on 12/03/11


Tagged


Versions (?)

datoteka pokazivač


 / Published in: C++
 

URL: program SP

datoteka s pokazivačima

  1. struct qu {
  2. elementtype value;
  3. struct qu *next;
  4. };
  5.  
  6. struct que {
  7. struct qu *front,*rear;
  8. };
  9.  
  10. typedef struct que queue;
  11. typedef struct qu *element;
  12.  
  13. bool IsEmptyQ(queue *element){
  14. if (element->rear == element->front) return true;
  15. else return false;
  16. }
  17.  
  18. elementtype FrontQ(queue *element){
  19. if (IsEmptyQ(element)){
  20. cout << "Red je prazan!" << endl;
  21. }
  22. return element->front->next->value;
  23. }
  24.  
  25. void EnQueueQ(elementtype x , queue *element){
  26. element novi , prethodni;
  27. novi = new qu;
  28. novi->value = x;
  29. prethodni = element->rear;
  30. prethodni->next = novi;
  31. element->rear = novi;
  32. }
  33.  
  34. void DeQueueQ(queue *element){
  35. if (IsEmptyQ(element)){
  36. cout << "Red je prazan!" << endl;
  37. exit(1);
  38. }
  39. element brisi;
  40. brisi = element->front;
  41. element->front = brisi->next;
  42. delete(brisi);
  43. }
  44.  
  45. void InitQ(queue *element){
  46. element el;
  47. el = new qu;
  48. el->next = NULL;
  49. element->front = element->rear = el;
  50. }

Report this snippet  

You need to login to post a comment.