Bubble Sort Algorithm in C

后端 未结 4 591
醉梦人生
醉梦人生 2020-12-22 13:31

The program I\"m trying to finish is a program using the bubble sort algorithm. I am not sure what is the problem or in which function the problem is in. The problem is th

4条回答
  •  春和景丽
    2020-12-22 14:03

    pretty sure your problem is with you algorithm, try to simulate your algorithm in pen and paper. it will help your understanding of your code and the algorithm better :)

    for your convenience here i am including a bubble sort algorithm i did some while ago

    void bubbleSort( int a[], int n)
    {
        int i,j,temp; // for a={1,2,3,4,5} n is 5
    
        n = n - 1;    // bcz otherwise it will get out of index
    
        for(i=0; ia[j+1])
                {
                    temp = a[j+1];
                    a[j+1] = a[j];
                   a[j] = temp;
                }
    
            }
    
        }
    
    }
    

    i hope this helps

提交回复
热议问题