c++ - wrong output for bubble sort feedback needed -
while testing of programme found out giving wrong output. have been trying find error cannot please help.
// bubble.cpp : defines entry point console application. //
#include "stdafx.h" #include <iostream> #include <stdlib.h> using namespace std; void bubblesort3 ( int x [ ] , int n ) { bool exchanges; int temp; { n--; //make loop smaller each time exchanges = false; // assume lastly pass on array ( int i=0; < n-1; i++ ) { if (x [ ] > x [ i+1 ]) { temp = x[ ]; x [ ] = x [ i+1 ]; x [ i+1 ] = temp; exchanges = true; // after exchange must 1 time again } } } while (exchanges); } int _tmain(int argc, _tchar* argv[]) { int array[4]={50,3,33,1}; bubblesort3 ( array , 4 ); (int i=0;i<4;i++){ cout << " "<< array[i]<< " "; } cout <<endl; system("pause"); homecoming 0; }
change line ( int i=0; < n; i++ ) work
c++
No comments:
Post a Comment