# BUBBLE SORT .....WHAT AM I DOING WRONG ??? :( ..help!:(

 rasel ahmed · December 12, 2015 ``#include #include #include using namespace std;class Prob1{private:    int i, x[10], s;public:    void ReverseTheArray(){        srand(time(0));        s =5;        int c =0;        for(i=0; i>x;          x= rand()% 10 ;          cout<

## Replies

 rasel ahmed · December 13, 2015 it will b x[ j ] = x[ j+1] ??? sherry dang · December 16, 2015 ... C C · December 21, 2015 i think you may have a problem on your 2nd line in your 2 for loops, should be x[j] = x[j+1]; instead of just x = x[j+1]look at my sample code for 10 integers: http://pastebin.com/P7Ky9XDc C C · December 21, 2015 and make your inner loop j , start from int j =1; Yaw Ofori · January 21, 2016 #include #include #include using namespace std;class Prob1 { int i, x[10], s;public: void Display() { //srand(time(0));//Don't know what this is doing. s = 5; int c = 0; for (i = 0; i < s; i++) {   x = rand() % 10;//Assignment to indexed array c++; cout << "number entered: " << c << " = " << x; cout << endl; }   cout << endl; cout << endl; int temp; //Arranges in ascending order. for (int i = 0; i x[j + 1]) { temp = x[j]; x[j] = x[j + 1]; x[j + 1] = temp; } } }cout << "\n\nDisplay array in ascending order: " << endl; for (int i = 0; i < s; i++) cout << x << "  "; cout << endl; } //Prints out the array /*void printarray() { for (int i = 0; i < s; i++) cout << x << "  "; cout << endl; }*/   //Reversing the array void ReverseTheArray() { int temp; for (int i = 0; i < s; i++) { for (int j = s; j < 0; j--) { if (x[j] > x[j + 1]) { temp = x[j];    x[j] = x[j + 1]; x[j + 1] = temp; } } } cout << endl; for (int i = s-1; i >= 0; i--)//just turns the array around(descending order) cout << x << "  "; cout << endl; }};int main(){ Prob1 o; o.Display(); //o.printarray(); cout << "\n\nThis is the reversed array: "; o.ReverseTheArray(); //o.printarray(); cout << endl; system("pause"); return 0;}
• 1

## C++

129,947 followers