# Tag Info

Accepted

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

preferences[pairs[i].winner][pairs[i].loser] > preferences[pairs[i+1].winner][pairs[i+1].loser] This condition swaps the elements in ascending order while check50 checks for the pairs array for ...
• 66
Accepted

### pset3 bubble sort

My sincere recommendation is ... start again. You have two nested loops, each time the DO-WHILE loop begins, the min and max values are set to zero, as the end-of-cycle condition for while is values[...
• 5,179

### Bubble Sort Time Complexity

When evaluating time complexity, it's about order of magnitude estimates, not exact precision. For this reason, n - c, where c is a constant, are generally treated the same It's the order of ...
• 69.1k
1 vote
Accepted

### Pset3 Plurality - not able to get the right output

You're right, the problem is in this code. It's your "bubble sort" code. It's not actually sorting the list, it's only bringing the top winner to the end, and it's corrupting the list in ...
• 69.1k
1 vote

### find problem with my code - CPU overload

You never update m or k, so the loop will go on. Move the l = (m + k) / 2; into the loop. And instead of calculating a different l in your actions, change m or k, and let l re-calculate on next ...
• 21k
1 vote
Accepted

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

Your search function never returns true. Ever. if (value == values[m]) { return 0; } return 0 is the same as return false. It should be return 1 or return true.
• 812
1 vote
Accepted

### Need help in code of bubble sort

you have this problem because you are storing this large number in an integer variable. You should use some other data type for such large values like long int or long long int, which can store the ...
1 vote

### find not working

To review, the bubble sort TODOs (according to the less-comfortable walkthrough) are as follows: iterate over list compare adjacent elements swap elements in the wrong order largest ...
1 vote
Accepted

### pset 3 bubble sort not sorting

void sort(int values[], int n) { void bubble(int values[], int n); } Here you just declare bubble function, but don't call it. Strange that you do not get an error like "unused parameter" while ...
• 1,139
1 vote

### Segmentation Fault pset3 for Find

Much better now. Your Binsearch works fine, but sort doesn't. Segmentation fault comes from here values[i+1] = values[max] As max is a value in haystack, not an index of haystack[]; Correct it and ...
• 1,139
1 vote
Accepted

### Segmentation Fault pset3 for Find

You have two problems here: First is that your sort function does not sort. Just look here, for example: if ((n<i+1) && (n>1)) This condition will NEVER be true as you loop for i < ...
• 1,139
1 vote
Accepted

### Pset3 - Problem with Bubble Sort

In your swap part, you assign to values[j] twice, second should be values[j+1]
• 21k
1 vote
Accepted

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

You have two problems with the last element, or the one just behind the array. In code for(i = 0; i < n && no_swap == false; i++) { no_swap = true; for(j = 0; j < ...
• 21k
1 vote
Accepted

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

First of all the do{} while loop and the sorted variable are redundant, you should remove them. Then, the for loops aren't properly initialized. What they should do is for i decreasing from n to 1 ...
• 51
1 vote
Accepted

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

The simple approach works. Just before the return, create a for loop and print out the array in order. Having said that, your sort isn't working. You do a great job of swapping j and k. The problem ...
• 69.1k
1 vote
Accepted

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

The problem here is that the code only makes one pass through the list. It will bubble the largest element to the end of the list, but then stops. It needs to come back to the beginning and repeat ...
• 69.1k
1 vote
Accepted

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

The condition for your for loop to begin running is that swab != true. However, when you initialized swab at the beginning of the value, you set its value to true. Under those conditions, the loop ...

Only top scored, non community-wiki answers of a minimum length are eligible