Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1.  
  2.  
  3. void push_queue(struct Node* tail, int val){
  4.  
  5. if(tail==head){
  6. struct Node* cur = (struct Node*)malloc(sizeof(struct Node));
  7. cur->val=val;
  8. cur->next =NULL;
  9. tail=cur;
  10. head->next = tail;
  11. }
  12. if(tail==NULL){
  13. head->val = tail->val = val;
  14. head->next = tail->next = NULL;
  15. }
  16. struct Node* cur = (struct Node*)malloc(sizeof(struct Node));
  17. cur->next = NULL;
  18. cur->val = val;
  19. tail->next=cur;
  20. tail = cur;
  21. }
  22.  
  23. struct Node* pop_queue(struct Node* head, int val){
  24. Node* cur = head;
  25. if(head==NULL){
  26. cout << "queue is empty" << endl;
  27. return 0;
  28. }
  29. head=head->next;
  30. return cur;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement