Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void xXx(Node*& stack)
- {
- Node* tmp = stack;
- double average = 0, count = 0;
- while (tmp != nullptr)
- {
- average += tmp->Value;
- tmp = tmp->Next;
- count++;
- }
- average /= count;
- Node* tmp2 = tmp = stack;
- Node* tmp3 = stack;
- while (tmp != nullptr)
- {
- if (tmp->Value < average)
- {
- if (tmp == stack)
- {
- stack = stack->Next;
- tmp = stack;
- delete tmp3;
- }
- else if (tmp->Next == nullptr)
- {
- while (tmp2->Next != tmp)
- {
- tmp2 = tmp2->Next;
- }
- tmp2->Next = nullptr;
- tmp3 = tmp;
- tmp = tmp2;
- delete tmp3;
- }
- else
- {
- tmp2 = stack;
- while (tmp2->Next != tmp)
- {
- tmp2 = tmp2->Next;
- }
- tmp2->Next = tmp->Next;
- tmp3 = tmp;
- tmp = tmp2->Next;
- delete tmp3;
- }
- }
- tmp = tmp->Next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement