0

Hi -- I am writing a program taht is supposed to input 12 integers into a program, sort them as they are entered, and then Print out the Sorted list. Second step is compute the average. I have done all that.

THIRD is to delete all the integers that are less than the average. I am having trouble with that part. The entire program is below and it runs great when I take out the "Delete less than " information in Int Main. I only get 2 errors, but still won't run. Can someone point me in the right direction? I am a beginner on Linked Lists.

Thanks

**************************************************

```
#include <iostream>
#include <fstream>
usingnamespace std;
//Functions
void GetData (int& number);
constint nil=0;
class node_type // Declaration of Class
{
public:
int num; // Numbers that we are entering
node_type *next;
};
int main ()
{
node_type *first, *p, *q, *newnode, *w; // Introducing the Nodes
int i;
int number;
int sum, average;
sum = 0;
first = new node_type;
p=first;
GetData(number);
(*first).num = number;
(*first).next = nil;
for (i=1; i<=11; i++)
{
GetData (number); // Input Numbers
newnode = new node_type;
(*newnode).num=number;
(*newnode).next=nil;
(*p).next = newnode; // Links previous Node to new Node //
p=newnode;
}
bool sw=false;
while(!sw)//you do this till there are no adjacent numbers in reverse order
{
sw=true;
if (first->num>first->next->num)
{
q=first->next;
first->next=q->next;
q->next=first;
first=q;
sw=false;
}
q=first;
while (q->next->next)
{
p=q->next;
w=p->next;
if (p->num>w->num)
{
q->next=w;
p->next=w->next;
w->next=p;
sw=false;
}
q=q->next;
}
}
q=first;
cout<<" The ordered numbers are: \n";
while (q != nil)
{
cout << (*q).num << "\n ";
sum = sum + (*q).num;
q = (*q).next;
}//endwhile
//Compute Average
average = sum/12;
cout << "The Average of the Numbers entered is " <<average<< "\n";
//Delete Nodes from List
if ((*first).num >=average)
{
cout << "Nothing to Delete \n" ;
}
else
{
q=first;
p=(*q).next;
while (((*p).next != nil)&&((*p).next < average))
{
q=p;
p=(*p).next;
}
//endwhile
if ((*p).num > average)
{
first = p;
}
else
{
first = nil;
}
}
//end if
//end if
//end if
return 0;
}
void GetData(int& number)
{
cout<< "Enter an integer \n";
cin>>number;
cout<< number << "\n";
}
```