Hello, first off I would just like to ensure that this is not for homework or anything like that because I am past the first class of cs111 where by now we should know how to do something like this already, I am just trying to make my own sorting method to have for the future so can anyone please help me on this? When it prints I get 0 so I don't see what I am doing wrong or where I am going wrong please help! Here is my code so far.
#include <iostream>
using namespace std;
int main(){
int a[4] = {0,1,2,3};
int b[4] = {4,2,1,0};
for(int i=0; i<=3; i++){ //read a[i] from left to right
for(int j=3; j>=0; j--){ //read b[j] from right to left
while(!b[j]==a[i]) // comparion
if(b[3]==a[3] && b[2]==a[2] && b[1]==a[1] && b[0]==a[0]); //comparison test
int temp=a[i];
a[i]=b[j];
b[j]=a[i];
cout << b[j];
}
cout << endl;
}
system("pause");
return 0;
}
Hey lb thanks, but anyway you can help improve my code? and smac89 thanks but i don't want some other code that's already out there would rather much appreciate it if you can help me improve my code?
You will have to explain the logic you are trying to apply to that sorting function of yours. It is taking over 8 seconds and still counting to sort an array containing 4 values. The reason for this is the while loop in the body of the second for-loop. What is this supposed to be doing?