-4

```
#include "queue.h"
#include <cstdlib>
using namespace std;
void queue::sort()
{
Node *nodeLeft, *nodeRight;
double temp=0;
int nofswaps=1;
if(size>1)//check that at least two nodes exists in the queue
{
while(nofswaps>=1)
{
nofswaps=0;
do
{
nodeLeft=pFront;//nodeLeft first time points to the first node of the queue and then points to next node each time the loop executes
nodeRight=nodeLeft->next; //nodeRight points to the next node of nodeLeft
if((nodeLeft->input)<(nodeRight->input))//if left node's value is smaller than right node's
{
//swap the values of left and right node
temp=nodeLeft->input; //contents of left node stored in variable temp
*nodeLeft=*nodeRight; //left node now contains the value of right node
*nodeRight=temp; //right node now contains the value of left node
nofswaps++; //increase nofswaps which counts how many swaps we had
}
pFront=pFront->next; //pFront will now point to the next node of queue
}while(nodeRight!=NULL);
}
}//end of if statement
}//end of compareNodes()
```

*Edited 7 Years Ago by miag*: n/a