Guest User

Untitled

a guest
Oct 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. int push_back(pos_t *head, int new_value) {
  2. pos_t *temp = head;
  3.  
  4. while (temp->next != NULL) {
  5. temp = temp->next;
  6. }
  7. pos_t *temp1 = (pos_t *)malloc(sizeof(pos_t));
  8. temp1->data = new_value;
  9. temp1->next = NULL;
  10. temp = temp1;
  11. }
  12.  
  13. if (temp1 == NULL) { return 1; }
  14.  
  15. int push_back(pos_t **headp, int new_value);
  16.  
  17. int push_back(pos_t **headp, int new_value) {
  18. pos_t *temp = *headp;
  19. pos_t *temp1 = malloc(sizeof(pos_t));
  20. if (temp1 == NULL) { // allocation failure
  21. return 1;
  22. }
  23. temp1->data = new_value;
  24. temp1->next = NULL;
  25.  
  26. if (temp == NULL) { // empty list
  27. *headp = temp1;
  28. } else {
  29. while (temp->next != NULL) {
  30. temp = temp->next;
  31. }
  32. temp->next = temp1; // append node to the end of the list
  33. }
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment