# Tag Info

Accepted

### Pset3 - Sort function not working

There is definitely a problem in the sort code. The logic is flawed because it is using min to store the minimum value at times and to store the index of the minimum value at other times. By mixing ...
• 69k
Accepted

### Finding the smallest value with Selection Sort

so I assume that you have an outer for loop that iterates over the elements of the array where i is the index of an element. you're trying to use min to keep track of the index of the minimum ...
• 17.7k

### PSET3:Find: Code works without the function, doesn't work with the function

C, by default, passes parameters to functions by value. That means when the function swap is called, two new variables, x and y are created, and the values of the integers are copied into them. When ...

### Selection Sort: Holes in Logic

The main problem is in the following statements: string answer = 0; answer[i]= min_value; Let's see if I can explain it clearly; a variable of type string is really a typedef (an alias in other ...
• 5,179
1 vote
Accepted

### CS 50 - pset3 find helpers: Why do binary search and selection short not work?

In my opinion, sort should use i < n - 1 not -2. In search, start = 0; end = n - 1; needs to go before the while loop, otherwise you would reset the interval each time, creating an infinite loop. ...
• 21k
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 ...
• 21k
1 vote
Accepted

### Pset3 Find - error in "helper" file - 'expected expression'

If you adjusted the indentation to match the curly braces, you'd realise that you put the else after the for loop, not one level higher after the if. You don't need that outer if, as your for loop ...
• 21k
1 vote
Accepted

### Pset 3: find - implementing selection sort function not working

arr[j]=smallest; In the above line you are assigning the value stored in variable smallest to the jth element in your array. So in the first iteration of the for loop the variable smallest is set ...
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+...
• 21k
1 vote

### What is wrong with my sorting algorithm?

Aren't you using smallell here without initializing it first? if (values [j] < values [smallell]) I only saw you declaring smallel here, but you never assigned a value to it: int smallell;
• 2,595

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