I am supposed to sort an array in ascending order..I have tried but then i cant get the results i want.I also tried to look it up in this forum but i still can't get it...Here is part of the code:

void sort()
{
	int size=10;
	int j,temp,i;
	for(i=0;i<(size-1);i++)
	{		
		for(j=i+1;j<size;j++)
		{
			if(queue[i]>queue[j])
			{
				temp=queue[i];
				queue[i]=queue[j];
				queue[j]=temp;
			}
			
		}
	}
	cout<<"Status: sorting done."<<endl;
	
 }

The result i getting is zero for everything...Please help me..

Where are you passing the contents of queue into your function?

Unless you're declaring it as global.
Also where is your print bit?

ok here is the whole code

# include<iostream>
using namespace std;


int queue[10];
int lastElement=-1;
void sort()
{
	int size=10;
	int j,temp,i;
	for(i=0;i<(size-1);i++)
	{		
		for(j=i+1;j<size;j++)
		{
			if(queue[i]>queue[j])
			{
				temp=queue[i];
				queue[i]=queue[j];
				queue[j]=temp;
			}
			
		}
	}
	cout<<"Status: sorting done."<<endl;
	
 }


void show(int size)
{
	int a=-1;
	for(int b=0;b<=lastElement;b++)
	{
		cout<<"Item "<<b<<": "<<queue[++a]<<endl;
	}
}
void subno(void)
{
	int sub=0,b=0,c=0;
	cout<<"Status: Last number successfully removed."<<endl;
	if(lastElement!=0)
	{
	queue[--lastElement];
	cout<<queue[0]<<queue[1]<<queue[2]<<queue[3];

	}
}
void addno(void)
{
	
	int b=0;
		cout<<"Enter number to add: ";
		cin>>queue[++lastElement];
		cout<<queue[0]<<queue[1]<<queue[2]<<queue[3];
}
void main(void)
{
	int b=10,c=0,e=0;
	int a=0;
	
		do
		{
			cout<<"Queue system [Free:"<<b<<"]"<<endl;
			for(int f=1;f<36;f++)
			{
				cout<<"=";
			}
			cout<<endl;
			cout<<"1. Add number to the end of queue."<<endl;
			cout<<"2. Remove number from end of queue."<<endl;
			cout<<"3. sort the queue in ascending order."<<endl;
			cout<<"4. show queue content."<<endl;
			cout<<"5. Quit."<<endl;
			cout<<"choice: ";
			cin>>a;
			cout<<endl;
		
		if(a==1)
		{
			addno();
			b--;
		}
		else if(a==2)
		{
			subno();
			b++;
		}
		else if(a==3)
		{
			sort();
		}
		else if(a==4)
		{
			show(10);
		}

		}
	
while(b!=0);

}

And what happens if you change:

void sort()
{
  int size = 10;
  int j, temp, i;
  for ( i = 0; i < ( size - 1 ); i++ )
  {
    for ( j = i + 1; j < size; j++ )
    {
      if ( queue[i] > queue[j] )
      {
        temp = queue[i];
        queue[i] = queue[j];
        queue[j] = temp;
      }
    }
  }
  cout << "Status: sorting done." << endl;

  for ( int i = 0 ; i < 10; i++ )
  {
    cout << queue[i] << " ";
  }
}

erm i get all zeros at the start then i get the number i keyed in but the numbers are sorted out.

Nothing wrong with the program. I tried it at my end.
Enter all ten array elements and then try.
If you do'nt want to add all the elements then

In the show() function change the line
for(int b=0;b<=lastElement;b++)
to for(int b=0;b<size;b++)

------ Pradhan

comment out both of these lines:

cout<<queue[0]<<queue[1]<<queue[2]<<queue[3];

in sort() change this:

int size=10;
nt j,temp,i;
for( i= 0; i < size - 1; i++)
{		
  for(j = i+1; j < size; j++)

to this:

int j, temp, i;
for(i = 0; i < lastElement; i++)
{		
   for(j = i+1; j <= lastElement; j++)

change show(int size) to show()
Then you should be able to work with any size queue having between 1 and 10 elements.
There are other changes I think you should make, too, but that should make it funtional enough for now.

This question has already been answered. Start a new discussion instead.