Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int push_back(pos_t *head, int new_value) {
- pos_t *temp = head;
- while (temp->next != NULL) {
- temp = temp->next;
- }
- pos_t *temp1 = (pos_t *)malloc(sizeof(pos_t));
- temp1->data = new_value;
- temp1->next = NULL;
- temp = temp1;
- }
- if (temp1 == NULL) { return 1; }
- int push_back(pos_t **headp, int new_value);
- int push_back(pos_t **headp, int new_value) {
- pos_t *temp = *headp;
- pos_t *temp1 = malloc(sizeof(pos_t));
- if (temp1 == NULL) { // allocation failure
- return 1;
- }
- temp1->data = new_value;
- temp1->next = NULL;
- if (temp == NULL) { // empty list
- *headp = temp1;
- } else {
- while (temp->next != NULL) {
- temp = temp->next;
- }
- temp->next = temp1; // append node to the end of the list
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment