//Exercise 6, call void removeOcc(List **head, int X){ List *p = *head; List *prev = NULL; while(p != NULL){ if((*head)->data == X){ *head = (*head)->next; free(p); p = *head; } else if (p->data == X){ prev->next = p->next; free(p); p = prev->next; } else{ prev = p; p = p->next; } } } //Exercise 7, call: mergeLists(L1, L2, &L3); void mergeLists(List* L1, List* L2, List** L3) { if (L1 == NULL) *L3 = L2; else if (L2 == NULL) *L3 = L1; else { if (L1->data < L2->data) { *L3 = L1; L1 = L1->next; } else { *L3 = L2; L2 = L2->next; } List* tail = *L3; while (L1 != NULL && L2 != NULL) { if (L1->data < L2->data) { tail->next = L1; L1 = L1->next; } else { tail->next = L2; L2 = L2->next; } tail = tail->next; } if (L1 != NULL) tail->next = L1; else tail->next = L2; } } //Exercise 8, call: splitList(L, &L1, &L2); void splitList(List* L, List** L1, List** L2) { *L1 = NULL; *L2 = NULL; List* tail1 = NULL; List* tail2 = NULL; while (L != NULL) { if (L->data % 2 != 0) { if (*L1 == NULL) { *L1 = L; tail1 = *L1; } else { tail1->next = L; tail1 = tail1->next; } } else { if (*L2 == NULL) { *L2 = L; tail2 = *L2; } else { tail2->next = L; tail2 = tail2->next; } } L = L->next; } if (tail1 != NULL) tail1->next = NULL; if (tail2 != NULL) tail2->next = NULL; } //Exercise 9, call: removeFirst(&head); void removeFirst(List** head) { if (*head != NULL) { List* p = *head; if (p->next == *head) { free(p); *head = NULL; } else { List* last = *head; while (last->next != *head) {last = last->next;} last->next = p->next; *head = p->next; free(p); } } } //Exercise 10, call: append(&head, val); void append(List** head, int val) { List* newNode = (List*)malloc(sizeof(List)); newNode->data = val; newNode->next = NULL; newNode->prev = NULL; if (*head == NULL) { *head = newNode; } else { List* p = *head; while (p->next != NULL) { p = p->next; } p->next = newNode; newNode->prev = p; } }