Untitled
unknown
plain_text
2 years ago
1.8 kB
7
Indexable
bool is_cycle_to_head(struct day *deleted_day,
struct date current_day_date,
struct date date) {
if (compare_date(current_day_date, date) == 0) {
if (deleted_day->next == NULL) {
return true;
} else {
return false;
}
}
return false;
}
struct day *remove_day(struct day *day_one,
struct day **current_day,
struct date date) {
if (compare_date(day_one->date, date) == 0) {
struct day *new_day_one;
free_crepes_of_day(day_one);
if (day_one -> next == NULL) {
struct date new_date = {2024, 1, 1};
new_day_one = create_day(new_date);
*current_day = new_day_one;
}
else {
new_day_one = day_one->next;
if (compare_date((*current_day)->date, date) == 0) {
*current_day = new_day_one;
}
}
free(day_one);
return new_day_one;
}
else {
struct day *current = day_one;
struct day *deleted_day;
while(current->next != NULL && compare_date(date, current->next->date) > 0) {
current = current->next;
}
if (current->next != NULL && compare_date(date, current->next->date) == 0) {
deleted_day = current->next;
if(is_cycle_to_head(deleted_day, (*current_day)->date, date)) {
*current_day = day_one;
} else {
*current_day = deleted_day->next;
}
free_crepes_of_day(deleted_day);
current->next = deleted_day->next;
free(deleted_day);
return day_one;
}
}
return NULL;
}
Editor is loading...
Leave a Comment