Gentlemen, help, I can not deal with the task.
It is required to remove the maximal element from the single-linked list. Here are two options for the function, none passes. Explain to me, cripple.
void delMaxValue(Stack **stck, int maxValue){ Stack *tmp = NULL; do { if ((*stck)->info != maxValue) tmp = *stck; cout << tmp->info << endl; tmp = tmp->next; *stck = (*stck)->next; } while ((*stck)->next != NULL); while (tmp != NULL) { *stck = tmp; *stck = (*stck)->next; tmp = tmp->next; } Another variant:
Stack* deleteMaxValue(Stack *begin) { Stack *t = begin, *p = begin->next; for (; p; p = p->next) if (p->info > t->info) t = p; p = begin; if (p != t) { while (p->next != t) p = p->next; p->next = t->next; } else begin = t->next; delete t; return begin; }
Thank you in advance, lads