Untitled
unknown
c_cpp
2 years ago
1.7 kB
6
Indexable
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_crepe_stand(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 (compare_date((*current_day)->date, date) == 0) {
if (deleted_day->next == NULL) {
*current_day = day_one;
} else {
*current_day = deleted_day->next;
}
}
free_crepe_stand(deleted_day);
current->next = deleted_day->next;
free(deleted_day);
return day_one;
}
}
return NULL;
}
void free_crepe_stand(struct day *day_one) {
struct crepe *current = day_one->orders;
struct crepe *next;
while (current != NULL) {
next = current->next;
free(current);
current = current->next;
}
}Editor is loading...
Leave a Comment