bubble-sort

Sorting in arrays

While sorting an array for ex: A[5]={1,4,5,3,2} the output must be 1,2,3,4,5 in ascending order. in using the concept of bubble sorting my output is 0,1,2,3,4 what would be the problem in my code int A[5]={1,5,3,2,4}; for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(A[j]>A[j+1]) { int t=A[j]; A[j]=A[j+1]...

Bidirectionnal Bubble Sort in Java?

I need to implement the bidirectional bubble sort in my code. In other words in will go from left to right first carrying the largest value. But when it reaches out, it should reverse and go from right to left carrying the smallest value. I am advised to to implement another out index in addition the current one. This is what I have...

What type of sort is this?

The C++ book I'm reading described a sort algo, saying it is the Bubblesort yet I cannot find a single variation of bubblesort just like it. I understand the differences are minor, but is it exactly as efficient as a regular bubblesort ? BubbleSort(int A[], int length) for (j=0; j < length-1; j++) for (i=j+1; i < length; i++) if (...

bubblesort from highest to lowest number in java

I'm looking for a bubblesort code in java that is opposite of the usual thing that I'm seeing when I search the internet. I don't really understand the code below, all I know is that it sorts a bunch of numbers from lowest to highest. Is the code below modifiable so that instead of outputting the numbers from lowest to highest. It outpu...

How to bubble sort through a text file in Java

How do I do a bubble sort in java, The text file looks like this: aaa 2 bbb 3 ccc 1 What I need to do is to loop through it and display the highest score to the lowest. When I run the code below, The numbers, are already sorted. and it will display 3, 2, then 1. But the name isn't in sync with the corresponding score, it will onl...

How to create a Generic Bubble Sorting in c#

I am currently working on making my own Generic Bubble Sorting which can easily sort Strings, int. Below is my Code for Normal Bubble Sorting.Can you help me out how to create a generic Method Of this? public static void BubbleSorting() { int Swap; for (int outer = Length; outer >= 1; outer--) { for (...