bubble-sort Questions
13
Solved
I would like to know how else I can optimize bubble sort so that it overlooks elements that have already been sorted, even after the first pass.
Eg. [4, 2, 3, 1, 5, 6] --> [2, 3, 1, **4, 5, 6**]...
Sabadell asked 24/4, 2013 at 14:48
18
I have made a bubble sort algorithm (sorta) using JS. It works sometimes, but the problem is that it only iterates through the array once. Here is my code:
function bubble(arr) {
for (var i = 0; ...
Axum asked 14/6, 2016 at 16:19
28
Solved
In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.
This is my attempt ...
Standoff asked 21/5, 2009 at 21:47
0
I wrote the bubble sort algorithm in JavaScript and Wasm using Rust and the JS code is faster than Rust code. How is this possible?
JavaScript code
import * as wasm from "wasm-comparisio...
Pernell asked 21/12, 2021 at 23:39
2
Solved
trying to write a Python function:
def compare_lengths(x, y, z)
which takes as arguments three arrays and checks their lengths and returns them as a triple in order of length.
For example, if the f...
Woodrowwoodruff asked 4/10, 2021 at 11:54
2
So I have edited it some and am getting almost exactly what I want. The only problem I am having now is that I am getting a line of output that I don't want. I feel like the fix here is simple but ...
Dislimn asked 6/3, 2021 at 20:38
2
It's possible to conceive of a modification to bubble sort where the "swap" occurs randomly with probability p, rather than by performing a comparison. The result could be called a "...
Ergot asked 17/3, 2021 at 13:24
7
Solved
This is my bubble sort code but I am confused why the output shows only 125.
int secondArray[] = {0, 1, 5, 2};
int num;
for (int i = 1; i < secondArray.length; i++) {
for (int j = 0; j < se...
Hogweed asked 27/6, 2018 at 22:31
3
Solved
Answering a question in SO, I stumbled into this problem:
(def x [7 4 8 9 10 54 55 2 23 30 12 5])
(defn insert-x
([sorted-coll x]
(insert-x sorted-coll x
(if (= (type sorted-coll) clojure.la...
Greenshank asked 3/12, 2020 at 11:39
5
Solved
I am learning bubble sort. And I tend to forget about the type of sort everytime. So I am trying to find the logical meaning of each sort so that it helps in recalling the logic of sort :
I could ...
Staff asked 25/6, 2015 at 19:47
2
Solved
I am developing backend project using node.js and going to implement sorting products functionality.
I researched some articles and there were several articles saying bubble sort is not efficient. ...
Kariekaril asked 25/5, 2020 at 7:43
3
Solved
I am trying to create an algorithm that shows each step of bubble sort, sorting one number at a time. I was was able to sort the number at the first index, but I need to figure out how to sor...
Harbaugh asked 31/1, 2020 at 19:53
6
Solved
How would you implement the following Bubble Sort algorithm in a functional (Java 8) way?
public static final <T extends Comparable<T>> List<T> imperativeBubbleSort(List<T> ...
Incised asked 24/12, 2014 at 16:36
17
Solved
int[] arr = {800,11,50,771,649,770,240, 9};
int temp = 0;
for (int write = 0; write < arr.Length; write++)
{
for (int sort = 0; sort < arr.Length - 1; sort++)
{
if (arr[sort] > arr[so...
Livelong asked 8/2, 2013 at 7:54
6
Solved
for (int front = 1; front < intArray.length; front++)
{
for (int i = 0; i < intArray.length - front; i++)
{
if (intArray[i] > intArray[i + 1])
{
int temp = intArray[i];
intArray[i] =...
Hohenlohe asked 13/7, 2012 at 20:16
2
I am trying to bubble sort a 2d ArrayList which has 7 columns in the inner list. The third column is the price. I am trying to compare the price column of the rows and swap the row having the great...
Joselow asked 21/1, 2019 at 4:12
3
The first:
for(int i=0;i<n-1;i++)
for(int j=n-1; j>i;j--)
if(a[j] < a[j-1])
swap(a[j], a[j-1]);
or the second:
for(int i=0; i<n-1; i++)
for(int j=i+1; j<n; j++)
if(a[j] <...
Clausius asked 11/5, 2016 at 12:49
3
Solved
I deduced the time complexity of bubble sort in its best case according to the mothod used in book ALGORITHMS 2.2. But the answer turned out to be O(n^2).
Here's my derivation, hope anyone can hel...
Asynchronism asked 20/9, 2012 at 3:49
1
Solved
I am trying to implement a bubble sort over any traversable container using the Tardis monad.
{-# LANGUAGE TupleSections #-}
module Main where
import Control.DeepSeq
import Control.Monad.Tardis
...
Nuno asked 21/11, 2017 at 15:41
9
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.
Suppos...
Parton asked 31/8, 2009 at 17:13
7
Please can you tell me what is wrong to this implementation of bubble sort algorithm in JavaScript?
for (var i=1; i<records.length; i++){
for (var j=records.length; j<1; j--){
if (pa...
Fenske asked 21/9, 2011 at 15:31
2
Solved
def bubble_sort_by nums
do_it_again = false
nums[0...-1].each_with_index do |item, index|
if yield(nums[index], nums[index + 1]) > 0
nums[index], nums[index + 1] = nums[index + 1], nums[inde...
Blubberhead asked 1/10, 2014 at 7:48
14
I'm trying to implement the Bubble sort method into an easy coding problem for Ruby, but I'm having some trouble. I understand the idea is to look at the value of the first element and compar...
Blooming asked 18/6, 2012 at 21:35
3
Solved
I want to sort an array of structures using the bubble sort algorithm and pointers in C.
I have a cars structure:
typedef struct{
char model[30];
int hp;
int price;
}cars;
and I allocate mem...
Barnes asked 15/4, 2015 at 20:22
1
Solved
My program stops to read anymore lines and ends the program after this procedure like its 'end.' after it (but its not) :
Procedure BubbleSort;
var i, j : integer;
begin
for i := 0 to count - ...
Bootless asked 12/4, 2015 at 21:18
1 Next >
© 2022 - 2025 — McMap. All rights reserved.