Advertisement
Guest User

helper

a guest
Nov 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1.  
  2. struct Queue{
  3.  
  4. BST * data;
  5. Queue * next;
  6.  
  7. };
  8.  
  9. int isEmpty(Queue * last)
  10. {
  11. if(last == NULL)
  12. return 1;
  13. else
  14. return 0;
  15. }
  16.  
  17. Queue * enqueue(Queue * last, BST * value)
  18. {
  19. Queue * temp = (Queue*)(malloc(sizeof(Queue)));
  20. temp->data = value;
  21.  
  22. if(isEmpty(last))
  23. {
  24. temp->next = temp;
  25. last = temp;
  26. }
  27. else
  28. {
  29. temp->next = last->next;
  30. last->next = temp;
  31. last = temp;
  32. }
  33. return last;
  34. }
  35.  
  36. Queue * dequeue(Queue * last)
  37. {
  38. if((last == NULL) || (last->next == last))
  39. {
  40. return NULL;
  41. }
  42. last->next = last->next->next;
  43. return last;
  44. }
  45.  
  46. BST * top(Queue * last)
  47. {
  48. if(isEmpty(last))
  49. return NULL;
  50. else
  51. return last->next->data;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement