3
votes
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 ...
2
votes
pset3 find: seg fault (int array won't initialize to 0s)
I used the debugger on it, and it looked perfectly fine. temp[0] to temp[65535] were initially 0.
Have you tried using debug50 on it, like ./generate 1000 50|debug50 ./find 127? Maybe the ...
2
votes
Accepted
Tideman sort_pairs function
I don't know for a fact because I don't know how the check50 testing works, but I'd bet it's because of that extra strength property. Your program works all together, but the individual functions don'...
2
votes
Accepted
CS50x helpers.c help with looping
Your sort is essentially correct. It does restart at the beginning of the list each time. The only problem is that it is going beyond the end of the array.
The array has n elements, numbered from ...
1
vote
Accepted
Pset 3 sort function won't swap
apparently, you're trying to implement selection sort. the problem appears to be with this condition
if (values[j] < values [i])
{
min = j;
}
are you sure you wanna update min every time ...
1
vote
Accepted
'redefinition of i' compilation error pset 3 sort
The syntax for loop consists of ; and not ,.
for (int i = 0 ; i < n ; i++)
{
// your stuff here
}
1
vote
Accepted
Problem with plurality
The problem is in this condition in your second 'for' loop: for (int c = 0 ; c < i - candidate_count - 1 ; c++). Let's see: Before execute the second loop i = 0 and c = 0. To run the code 'c < i ...
1
vote
Accepted
tideman pset3 sort pairs - code doesn't work
For the selection sort, you have to reset biggest (and depending on your choice for the initial value, also loc) at the start of the outer loop.
1
vote
Accepted
Pset3: Tideman sort_pairs not work
Check with strengths 1, 3, 2, in that order, with the highest value not being last.
When you update max_index, you should also update diff. Otherwise, a later pair might be chosen that's stronger ...
1
vote
Accepted
check50 claiming pairs are sorted incorrectly
I suspect this "introduced another global array called strength_of_victory" is the problem. Recall from the spec:
You should not modify anything else in tideman.c other than the
implementations ...
1
vote
Accepted
Find's sort: instructions vs code: O(n) or O
Follow the spec. The problem uses the same distro code for both the "less" and "more" versions, so the TODO is based on the "less" specs.
1
vote
Accepted
Purpose of sizeof(book)/sizeof(string) in lectures' binary sort?
That code calculates the number of elements in the array book[]. sizeof(book) is the total size of the array, 72 bytes. Next, remembering that this is an array of pointers to strings ( the CS50.h ...
1
vote
Pset 3 -> Counting Sort - need tips to find my error
If you array is declared with 65536 buckets, then aux_list[65536] is outside the bounds (remembering that arrays are zero-indexed). So what happens in your loop when i == 65536?
1
vote
Accepted
Question about Bubble Sort
Hmmm.... Do you think that maybe the code inside the inner loop (the if statement and its code block) should be based on c instead of i?
If this answers your question, please click on the check ...
1
vote
PSET3 find having trouble. Can someone help?
The
array[start] < array[end]
is the wrong condition. You want to keep looping as long as the search interval has elements, so use
start <= end
instead (<= as you chose both start and ...
1
vote
Accepted
CS50 Helpers.C Find Less, No Idea What's Going On
Both search and sort have problems. First, sort isn't complete. It only makes one pass through the list, so it will only bubble sort the largest value to the last position. I suggest a review of the ...
1
vote
PSET 3, there is nothing happening
Your do..while loop really should be a regular while loop, but it would blow up only if your array to search was empty (then you're accessing values[-1] within the loop).
Your condition is wrong. ...
1
vote
Accepted
Segmentation fault for pset3 sorting
The code creates the counter array:
int counter[65535];
but doesn't initialize it. What is in the array? Try printing out the contents of the array (or maybe the first 20 elements) ...
1
vote
Accepted
pset3 helpers.c (help)
You are comparing to element values[(n+1)/2], but your recursive calls look like you meant values[n/2] instead, which makes a lot more sense, as n/2 is always the middle element's index, or the higher ...
1
vote
Accepted
pset3 - find less / sort video availability
The URL should be updated in the spec shortly. Here it is in the meantime:
https://www.youtube.com/watch?v=TYnkJckP1Ss
1
vote
Accepted
Pset3 - Find: I can't find what's wrong with my sorting algorithm...?
In search, move the calculation of mid into the loop, and make sure the /2 is outside the parentheses.
The sorting algorithm has no potential for an infinite loop, and looks correct.
Also, it's ...
1
vote
Accepted
is this function correct? CS50 Pset3 (Find)
There are problems here. First, it only makes one pass through the array, so all it will do is push the largest value to the end. The rest of the list will likely not sort. Next, since i can increase ...
1
vote
Accepted
pset3: sort -- Selection Sort Implementation
Looks like some kind of select sort. For that to work, in the outer loop, before the inner loop, set min to i ("smallest non-sorted element so far is at index i"), and in the inner loop (starting at i+...
1
vote
Pset3 - my bubble sort breaks the find function
If the list is not already sorted, you have an infinite loop. the counter variable will be incremented at some point, meaning that the while condition is true. Since counter is only incremented and ...
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 ...
1
vote
Accepted
Help with sorting function
The above code is partially correct. Although the logic seems to be appropriate, it is not efficient. All you have to do is set the value of i as minimum every time you enter the 'i' loop, and then ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sort × 68pset3 × 54
find × 19
search × 13
helpers × 6
cs50x × 5
bubble-sort × 5
c × 4
binary-search × 4
bubble × 4
segmentation-fault × 3
tideman × 3
gdb × 3
binary × 3
selectionsort × 3
check50 × 2
week3 × 2
algorithm × 2
check × 1
array × 1
pset × 1
runoff × 1
help × 1
plurality × 1
structs × 1