0
// 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

4
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by a.muqeet khan
0

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 by Taywin: n/a

0

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...

0

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

0

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

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.