bubble-sort

What is a bubble sort good for?

Do bubble sorts have any real world use? Every time I see one mentioned, it's always either: A sorting algorithm to learn with. An example of a sorting algorithm not to use. ...

Why is my bubble sort in Python so slow?

I have the following code thats use bubble sort to invert a list and has a worst time performance: for i in xrange(len(l)): for j in xrange(len(l)): if l[i]>l[j]: l[i], l[j] = l[j], l[i] In some cases (when len(l) = 100000) the code spend more then 2h to complete execute, I think its so strange, please correct ...

Best Case for Bubble Sort

I want to know what will be the best case for a bubble sort ? There may be a case wherein there may be no swapping for the say last 2 passes for example. I'm doing my program in C language. Suppose i have an array of 5 elements and i give the elements as 1 2 5 4 3 then there would be no change in the last 2 passes? ...

What's the most elegant way to bubble-sort in C#?

Can this be cleaned up? using System; class AscendingBubbleSort { public static void Main() { int i = 0,j = 0,t = 0; int []c=new int[20]; for(i=0;i<20;i++) { Console.WriteLine("Enter Value p[{0}]:", i); c[i]=int.Parse(Console.ReadLine()); } // Sortin...

Various ways of implementing bubble sort?

How should I implement the classic bubble sort algorithm? I'd particularly like to see a C++ implementation, but any language (even pseudocode) would be helpful. P.S. Not a homework. ...

How to fix this bubble sort program?

package arraySort; import java.io.IOException; import java.io.File; import java.util.*; public class openFile { int x; static int i; static int[] myList = {100}; public static void main(String[] args){ try{ File myFile = new File("arraySort.txt"); Scanner scan = new Scanner(myFile); ...

Bubble-Sort with 2D Array

Howdy, I do know how to implement a simple bubble-sort for 1dimensional array. But with 2dimensional or multidimensional, that's where I have my problems. So far I've been using this to sort 1Dimensional Arrays, works like a charm. But mostly with integer numbers, not strings: boolean sort; do{ sort = true; for (int i = 0; i < test...

Sort Ascending or Descending inside a Bubble-Sort

After this was answered I continued to work my way through the code. It work's perfect this way: static String[][] bubbleSort(String customerdata[][], int sortafter, int asc) { String temp []; boolean sort; do{ sortiert = true; for (int i = 0 ; i < customerdata.length - 1; i++){ if(customerdata[i][sortafter].compa...

parallel Bubble sort ....please HELP...

i write a c++ code for Bubble sort algorithm and i dont know how to make it parallel using openmp so please help me ..... this is the code : #include "stdafx.h" #include <iostream> #include <time.h> #include <omp.h> using namespace std; int a[40001]; void sortArray(int [], int); int q=0; int _tmain(int argc, _TCHAR* argv...

How do you use a bubble sort with pointers in c++?

So here's what I have so far: void sortArray(int amountOfScores, int* testScores) { for(int i = 0; i < amountOfScores; i++) { for(int j = 0; j < amountOfScores-1; j++) { if(*(testScores+i) > *(testScores+j+1)) { int temp = *(testScores+j); *(testScores+j) = ...

C++ sort array of char pointers

Can you tell me what's wrong with my method? I ends up putting the same thing everywhre and it's actually not sorting. void sortArrays(){ int i, j; for(i=0; i<counter; i++){ for( j=0; j<i; j++){ if( strcmp(title_arr[i], title_arr[j]) < 0){ char* title_temp = title_arr[i]; ...

Bubble sort algorithm implementations (Haskell vs. C)

Hello. I have written 2 implementation of bubble sort algorithm in C and Haskell. Haskell implementation: module Main where main = do contents <- readFile "./data" print "Data loaded. Sorting.." let newcontents = bubblesort contents writeFile "./data_new_ghc" newcontents print "Sorting done" bubblesort list = sort li...

Problem implementing sorting algorithm in C with an array of structs

Well here is my little problem, first my code: struct alumn { char name[100]; char lastname[100]; int par; int nota; }; typedef struct alumn alumn; int bubble(alumn **arr, int length) { int i,j; alumn *temp; for (i=0; i<=length-2; i++) { for (j=i+1; j<=length-1;j++) { if ((*arr)[i].nota > (*arr)[j...

Algorithm for max integer in an array of integers

Explain which algorithm you would use to implement a function that takes an array of integers and returns the maximum integer in the collection, assuming that the length of the array is less than 1000. Would you use Bubble Sort or Merge Sort and Why? Also, what happens to the above algorithm choice, if the array length is greater than 1...

J: Self-reference in bubble sort tacit implementation

Hello people! Since I'm beginner in J I've decided to solve a simple task using this language, in particular implementing the bubblesort algorithm. I know it's not idiomatically to solve such kind of problem in functional languages, because it's naturally solved using array element transposition in imperative languages like C, rather th...

Strange Bubble sort behaviour.

Can anyone explain why this bubble sort function doesn't work and why I lose numbers in my output? I'm very new to C, so please forgive me if this is something very obvious I have missed. #include <stdio.h> #include <stdlib.h> int bubble(int array[],int length) { int i, j; int temp; for(i = 0; i < (length); ++i) { for(j = 0...

Sorting 2D array of chars C++

I have a 2d array of chars where in each row I store a name... such as this: J O H N P E T E R S T E P H E N A R N O L D J A C K How should I go about sorting the array so that I end up with A R N O L D J A C K J O H N P E T E R S T E P H E N These is a 2d array of chars..... no strings or char points..... ...

JavaScript BubbleSort

Hi, Have a bubblesort routine similar the this. I need to make it more efficient by stopping the loop when the array is sorted or if the array is already sorted. function sortNumbers(listbox) { var x, y, holder; // The Bubble Sort method. for(x = 0; x < ranarray.length; x++) { for(y = 0; y < (ranarray.length-1); y++) { ...

what's bubble sort good at?

Possible Duplicate: What is a bubble sort good for? I'am sure every algorithm has its advantage and disadvantage, so how about buble sort compared to other sorting algorithm? (ofcourse I hope the answer is other than "easy to learn") ...

C++ Bubble sorting a Doubly Linked List

I know bubble sort is probably not the fastest way to do this but its acceptable. i'm just having trouble with adjusting the algorithm to double link lists from arrays. My double linked lists have a type int and a type string to hold a number and a word. My list was sorted with an insertion sort that I wrote to sort alphabetically, now ...