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
#include
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<next;
}
cout<info;
p=p->next;
}
aver=(double)sum/number;
cout<<"Average value= "<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"<>n;
for(int i=0; i
↧