# Questions tagged [bubble-sort]

The tag has no usage guidance.

39 questions
Filter by
Sorted by
Tagged with
594 views

### Bubble sort - omega or lower bound

In the 3rd lecture of Wednesday, it was said that for bubble sort, lower bound or omega will be 'n'. But shouldn't it be (n-1)? Suppose if list to sort is (1, 2, 3, 4) then it would take me 3 ...
122 views

### 3 days failing to get bubblesort working .. devastated :(

i am a beginner, i got linear search working quite fast.. but then total stuck. i tried to write function test, that gives me some random numbers and sort them. I watched all the videos and thought ...
33 views

### Need help in code of bubble sort

i've tried to make a bubble sort, but it does not work well. When i try to sort large numbers, the programm issues wrong numbers. With small numbers all is okey. Sorry for my bad english. My code is ...
124 views

### Pset3: Tideman sort_pairs doesn't work?

I know this has been asked before but I've checked every thread and couldn't find a solution. According to check50, my code for sort_pairs() doesn't work, and I can't figure out what could be wrong ...
17 views

### Bubble Sort Time Complexity

I have a question regarding the worst case bubblesort time complexity. What I have understood from David's lecture is the following: Let's say we have an array of 4 elements, sorted in reverse order ...
127 views

### pset3 bubble sort

pls could anyone tell me where have i made the mistake?...as i have tried to find it myself but couldn't find it. void sort(int values[], int n) { int min=0,max=0; do{ //to compare ...
157 views

### Segmentation Fault pset3 for Find

I'm getting a segmentation fault error and I can't figure out why. void sort(int values[], int n) { // TODO: implement a sorting algorithm for (int i = 0; i<n; i++) { if ((n!=i+...
69 views

### Bubble Sort not sorting generate numbers

Similar questions asked many times but I'm working on this endlessly without success so need your help void sort(int values[], int n) { // TODO: implement an O(n^2) sorting algorithm int i,j,...
279 views

### Why is my do..while loop executing only once?

I have tried to use a do-while outer loop with a for inner loop to implement bubble sort, but it appears to be executing once through the for loop and then not satisfying the while condition. The ...
31 views

### find problem with my code - CPU overload

I cannot figure out what is wrong with my code. /** * Returns true if value is in array of n values, else false. */ bool search(int value, int values[], int n) { // ensures that the n is non ...
69 views

### pset3: sort and search work in separate files, but my helpers.c doesn't work

I dealt with sorting in a separate file first, and then I dealt with searching in another file. They seem to work okay or at least worked for the numbers I feed in, but when I put them in helpers and ...
61 views

### find not working

so ive cleaned up my code but it still always prints 'found needle in haystack'! please help! /** * helpers.c * * Helper functions for Problem Set 3. */ #include <cs50.h> #include <...
121 views

### pset 3 bubble sort not sorting

I'm pulling my hair over the bubble sorting code that just won't work. Here is my pseudocode: for all elements in list size n excluding the last elements if values(i) > values(i+1) swap ...
191 views

### Pset3 - Problem with Bubble Sort

I've tried to write an implementation of bubble sort. I deliberately created it in a separate file outside of helpers.c, just to make sure it works, before incorporating into helpers.c It doesn't ...
56 views

### pset3 buble sort() function works but it gives wrong output in helper.c

this is my bubble sort program which works fine: #include <stdio.h> #include <stdbool.h> /** * Sorts array of n values. */ void sort(int values[], int n) { bool no_swap = false; ...
55 views

### Bubble sort isn't sorting. I think my counter may be to blame

void sort(int values[], int n) { int sorted; do { sorted = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < i; j++) { ...
342 views

### How do I test sort function in helpers.c pset3?

I am having trouble testing my bubble sort algorithm. I have used gdb but the output from gdb isn't telling me anything I understand at this point (even after reading several tutorials, etc.) Find.c ...
68 views

### is my swap function breaking my bubble sort implementation?

I'm trying to implement the bubble sort algorithm in pset3, but it's not working! Pretty sure it's because of failure to swap. Been working on it for a while, with no success. Here's the relevant code:...
55 views

### what is wrong with my implementation to bubble sort?

I was just practicing and thought about writing a code for bubble sort. can anyone tell me why this code is not giving me the desired output and what could be the possible solution to it? bool swap = ...
68 views

### Why are the sorted numbers not being printed out?

I'm trying to sort and print out the results, but it is showing nothing. I'm sure my implementation of bubble sort is correct. Where do you think is the error? I also modified the helpers.h to ...
348 views

### Bubble sort PSET3

I run gdb with the following commands: gdb ./find ; break sort ; run 42 < numbers.txt ; print values[0]@n. However, the numbers remain unsorted. Can someone help me? void sort(int values[], int n)...
135 views

### Please. I need some help. When I use Makefile (make) it wont work

#include <cs50.h> #include <math.h> #include "helpers.h" bool search(int needle, int haystack[], int size) { int min = 0; int max = size; while(max >= min) { ...
86 views

### Pset3 BubbleSort not sorting at all

I am trying to implement bubble sort, but in the end, the list isnt sorted at all. It looks like this, and I cant find the error: void sort(int values[], int n) { //Printing unsorted list ...
123 views

### Swap initialised in Bubble sort

I watched the Section video in week 3 which discussed Bubble sort. I also watched the lectures and the shorts on it. I understand how it works, except for one bit. I'm confused on the below image from ...
35 views

### PSET3 Plurality trouble. All of the checks on check50 work except 1!

I am having trouble figuring out what is wrong with my code. The only failure in check50 is (:( print_winner identifies Charlie as winner of election Cause print_winner function did not print winner ...
15 views

### Bubble sort not working

Bublesort <p id= "notiz">Hello World!</p> <script> document.getElementById("notiz").innerHTML = "The results of Bubblesort:<br>"; var mannschaft = ["Leander", "...
190 views

### pset3 help with find, bubble-sort and search

I've been struggling for over a week with this and can't figure out how to get my program to pass check50. I'm getting very interesting mixed results from check50: :) helpers.c exists. :) helpers.c ...
36 views

### Bubble sort code works, but does not stop

I fixed my bubble sort code, and it correctly sorts the numbers, but it does not stop when it should. My code is: #include <cs50.h> #include <stdio.h> #include <stdlib.h> //#...
45 views

### Help fixing bubble sort

I've been working on implementing a bubble sort, and I can get it to swap one time through the list, but I can't get it to run more than once, and I'm not sure how to implement it. I also know that ...
42 views

### Is this a correct way of implementing bubble sort?

I made a bubble sort code, but I want to make sure that my code is correct. My code is void sort(int values[], int n) { if (n == 1) { return 0; } int swapcount = 0; ...
236 views

I have created a separate file to test my bubble sort algorithm for pset 3. The file compiles but when I run it, it just prints out the elements in the array in their original order! Can someone ...
93 views

### Pset3 Find - Not sure what is wrong with helpers.c code

I am not sure what is wrong with the code. It seems to work on some of the criteria when using cs50's check50, but does not work on others. There also does not seem to have a pattern about the wrong ...
161 views

### helpers.c passes check50 but fails ./generate 1000 50 | ./find 128

check50 gives me all smiles, but when I run the test code ./generate 1000 50 | ./find 127 or 128 they both return "Found needle in haystack". How is that possible? And also, can I be sure my code is ...
91 views

### pset3: How to test sort function code using passed array and printf in independent file

I just wrote some code for a bubble sort function. I would like to test it using a simple printf with an array of values passed into it but am struggling. For now, let's assume that this file is ...
110 views

### Receiving an expected expression error on pset3 (curly braces match)

Tad bit confused as to why I'm receiving an expected expression error. I've looked at other questions for help on this, but the solution seems to be the curly braces. I've actually done this, and I'm ...
132 views

### What is wrong with my bubble sort implementation?

I implemented a bubble sort solution for pset3-sort. It works when I call the function from a test file I made, but when I print out the values of values in find.c it gets printed out unsorted. I've ...
765 views

### pset3 - Bubble sort not working

I'm stuck on pset3. I'm trying to implement bubble sort but somehow its not sorting at all. Here's my program. And here's the output. Thanks.