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

All 8 Replies

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

i dont know all i am doing is that i am sorting it out that all with my own failed logic

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

well i self studying programming no one is teaching me

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

thanks guy i have done it thank you so very much

Be a part of the DaniWeb community

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