Hello!
I need some help.
I must do the following task: create a one-way queue with numbers in the range from -50 to +50. After creating the queue, perform the following: find the average value of all queue elements and delete all elements that are less than the average value. At the end of the job, all queues must be deleted.
I was able to write code to create a queue, delete it, and find the average value of all the elements.
However, I can not implement the function of removing elements in the queue that are less than average.
Please help me write this function to remove elements that are less then average value of all the elements of the queue, I will be very grateful for your help!
Code:
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
using namespace std;

struct queue{            
	int info;			
	queue *next;			
}*b, *e;             

void AddQueue (queue **b, queue **e, int in)
{
	queue *t=new queue;   
	t->info=in;          
	t->next=NULL;        
	if (*b==NULL) 
		*b=*e=t; 
	else {        
		(*e)->next=t;
		*e=t;
	}
	return;
}

queue *ReadQueue(queue *t, int &in)   
{
	if (t==NULL)
	{
		cout<<"Queue is empty!\n";
		return NULL;
	}
	while (t!=NULL)
	{
		in=t->info;
		cout<<in<<" ";
		t=t->next;
	}
	cout<<endl;
	return t;
}

void Average(queue *k, queue *e)
{
	queue *p=NULL;
	int number=0, sum=0;
	double aver;
	p=b;
	while(p!=NULL)
	{
		number++;
		sum+=p->info;
		p=p->next;
	}
	aver=(double)sum/number;
	cout<<"Average value= "<<aver<<endl;
}


void DeleteQueue (queue **b, queue **e)  
{
	queue *t;
	while(*b != NULL)
	{
		t=*b;
		*b=(*b)->next;
		delete t;
	}
	*e=NULL;
}

int _tmain(int argc, _TCHAR* argv[])
{
	b=e=NULL;
	queue *t=NULL;
	int inf, n;
	double sum;
	cout<<"Input the number of elements"<<endl;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		inf=rand()%100-50;
		AddQueue(&b, &e, inf);
	}
	cout<<"Queue is: "<<endl;
	ReadQueue(b, inf);
	
	Average(b, e);
	ReadQueue(b, inf);
	DeleteQueue(&b, &e);
	if(b==NULL)
		cout<<"Queue was deleted"<<endl;
	return 0;
}
I really need your help!