Bubble Sort :: Forum

Start Date Last Update Igniter Last Update By Status
9:00am on Monday 25th November 2013 11 years ago

abedhorani

suzzett




abedhorani

Hello Everyone ,



Im new at Programming and i would like some help please im Have to write a programm that Sorts number given by a user from the Smallest to the biggest ( I think You all know what a Bubble sort is !!) i tried something but its not really working. if you could give me tips that would be great thanks Very much





abedhorani
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
    
    int i;
    int X= -1;
    cout<< "Enter the number of elements = ";
    cin>>Y;
    int Y;
    int z =i;
    int array[i];
    for (int a=0;a<i; a++)
    {
        cout<< "Enter the  "<<a+1<<"."<< "Element  "<<"=";
            
        cin>> array[i];
                    
    }
    
    for( l=i+1; l > 0; l--)
    {
        for (i = 0 ; i <= Y-1; i++)
        { 
            if(array[i]> array[i +1])
            {
                X = array[i+1];
                array[i+1] = array[i];
                array[i]=X;
            }
        }
        Y--;
    }
    for ( i=0; i<z ;i++)
    {
        cout<< array[i]<<", ";
    }
    cout<< endl;
    return 0;
}



abedhorani
This is what i wrote Please if anyone has any tipp hint anything that is really appreciated

thanks in advance




suzzett

So, what exactly is the problem/error you are getting in your program?



First thing is that cmath is not required to get included in this program. Second thing is that the variable Y is declared after it is used in line 10. So, line 10 and 11 needs to be swapped. And finally, variable l in line 22 inside for is not declared. These are simple compiler errors. Make sure that these are correct first and then see if it works.



Please login to post your reply!
 

Login

Username:
Password:
Don't have an account?
Register here
Register

Subscribe Youtube



Network DigitalStage.org


Some interesting stuffs