// algo assignment.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
 using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	int DATA[5];
	DATA[0]=0;
	DATA[1]=10;
	DATA[2]=80;
	DATA[3]=1;
	DATA[4]=5;
	int a;int temp; int i,j; 

	
	for (i=0;i<5;i++)
	{     
	 temp=DATA[i];  // at starting it means that it has value zero
		for (j=i+1;j<5;j++)
		{
			
		  if(temp>DATA[j] )
		   
		  { temp=DATA[j];
		  
		  a=DATA[j-1];
		  
		  DATA[j-1]=DATA[j];

		  a=DATA[j];}
		}
		  
		  
		cout <<DATA[i]<<endl;
	
	
	}
	
			
			
			
			
			
			
			system("PAUSE");

the main purpose of this program is that i just want to sort the array in an order and it is not going like that

What sort algorithm are you using in this case? Even though it looks like a bubble sort to me, I am still not sure.

Edited 5 Years Ago by Taywin: n/a

Then you should read the link in my previous post and look at the algorithm (pseudo code). Compare that to yours and adjust it. Then your sort should be OK. I don't understand how an instructor would give you a sorting assignment without giving or discussing about it at all...

OK, then you need to read the link I posted in my first post first before you try to implement a sort function. ;)

As @Taywin suggested, the error is in your sorting...

Seems like you have mixed Bubble Sort and Selection sort algorithms.

You just do your code on paper.. then you will find out already. *When you do, must follow code not follow what you planned.

It's a sequence problem...

This article has been dead for over six months. Start a new discussion instead.