#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()
Narue commented: Sorry, I don't have enough time to care. Hopefully you'll fail and learn to manage your time better instead of looking for a savior. -4

Recommended Answers

All 4 Replies

whats the first while for??

i think the problem is in line 31 bcause after the first time the pointer points at null

shouldn't use pFront = node_name.front()??
show the hole code

i think the problem is in line 31 bcause after the first time the pointer points at null

you could use an intregrer comparation instead... while(intr <= size)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.