Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2011
    Location
    Pakistan
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Bubble sorting try

    i m trying to make a program for bubble sort the code is
    [code]
    #include<iostream.h>
    #include<conio.h>

    main()
    {
    int size;
    cout<<"Enter the size of array: ";
    cin>>size;
    cout<<endl;
    int arr[size];
    for(int i=0;i<size;i++)
    {
    cout<<"Enter the number in "<<i+1<<"th Index: ";
    cin>>arr[i];
    cout<<endl;
    }
    for(int j=0;j<size-1;j++){
    for(int k=0;k<size-j;k++){
    if(arr[k]>arr[k=1]){
    int temp=;
    temp=arr[k];
    arr[k]=arr[k+1];
    arr[k+1]=temp;
    }
    }
    }
    for(int m=0;m<size;m++)
    {
    cout<<"Your "<<m+1<<"th array is "<<arr[m]<<endl;
    }getch();
    }
    [code\]
    but its having bug...
    dont know where?

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Well this is wrong:
    Code:
    if(arr[k]>arr[k=1]){
    It should be:
    Code:
    if(arr[k]>arr[k+1]){
    And please try and give more details in the future when posting a problem. Saying it has a bug isn't very descriptive.
    OracleGuy

  • #3
    New Coder
    Join Date
    Nov 2011
    Location
    Pakistan
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Unhappy

    Well...
    i tried u correction but as before it promp the user to take values but do not generate the result of sorting.......


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •