Questions tagged [sort]

The tag has no usage guidance.

20 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1 vote
1 answer
3k views

pset3: selection sort and binary search

I've been trying to implement those two function whole day and something seems to not be working because the printf function I wrote in find.c outputs 9,8,7,6,5,6,7,8,9 when I input the numbers from 9 ...
Petar Petrov's user avatar
1 vote
1 answer
1k views

How to use swap?

I am currently in pset3, implementing sort. I chose to do selection sort and at the end of it I need to swap the numbers, but when I try to compile, I get this message: implicit declaration of ...
Talita Maria Briganti Barbosa's user avatar
0 votes
1 answer
118 views

practice problems week 3. Sort temperature. And my result is all the temperature is sorted but the name of the city is not

void sort_cities(void) { // Add your code here for (int i = 0; i <= NUM_CITIES - 1; i++) { if (temps[i].temp < temps[NUM_CITIES - 1].temp) { int temp = ...
Nathan Doan's user avatar
0 votes
1 answer
92 views

Problem Set 3 (Runoff) print_winner function doesn't print and quits

I am working on problem set 3 runoff and I am having trouble with getting my print_winner function to work correctly. When I run the program it basically does nothing and quits the program. It gets ...
Dre Johnson's user avatar
0 votes
1 answer
101 views

Can you help me to understand why does the output of time function vary every time while applying it on same file with same sort type?

When I run for example (time ./sort1 random5000.txt) it gives me real, syst, and user time. But if I run the same command again it will gives me different time results! I can't understand why this ...
Aya Othman's user avatar
0 votes
1 answer
91 views

Trying to understand the insertion sort algorithm

While I was working on the PSet3, I've realized that I don't really understand the insertion sort algorithm the way it is presented in one of the short CS50 videos. So I commented out each line of ...
jiayou's user avatar
  • 17
0 votes
1 answer
53 views

pset3 find code works, despite 'sort' failing

I'm very confused! I have spent many (MANY) hours working through this pset. I've gotten to the point where my code passes all check50 requirements for 'find', but it's failing the 'sort' ...
Alex's user avatar
  • 7
0 votes
1 answer
43 views

pset3 keeps returning 1 even when it should return 0

bool search(int value, int values[], int n) { // TODO: implement a searching algorithm if (value < 0) return false; int s = 0; int e = n - 1; int m = ((s + e) / 2); while (s <= e) { ...
AMtman's user avatar
  • 1
0 votes
1 answer
28 views

How to "update" the haystack array not using pointers?

Context: In helpers.c, I can make the sort function actually sort the values[] array. Problem: However, I don't know how to re-inject this sorted array back in main without using pointers. Question: ...
ebosi's user avatar
  • 101
0 votes
1 answer
50 views

Check 50 for find

I have gotten most of my code to work for the search and sort, but I still have a few issues. One is i my for loop, I have it set to less than 100, though I need to make it less than log n, but I ...
Joel Banks's user avatar
0 votes
1 answer
255 views

How does one print out all existing integers in an int array?

The code below generates the following error: format specifies type 'int' but the argument has type 'int *' [-Werror,-Wformat] printf("%i", array); include include int main(void) { int ...
Drusk's user avatar
  • 3
0 votes
2 answers
114 views

Help finding segmentation fault

In my code, I get a segmentation fault some, but not all of the times that I run it. Sometimes, it sorts the code and finds the needle, sometimes it doesn't sort correctly and ends with a segmentation ...
Joel Banks's user avatar
0 votes
1 answer
65 views

is my selection code correct?

I used printf to check the process and final result. The final result is technically correct (the array is sorted in ascending order) but I saw the behaivior of the algorithm and it doesnt look like ...
Kev Lozano's user avatar
0 votes
1 answer
535 views

CS50 Problem Set 3 Helpers.c PROBLEMS

I have been trying to solve Pset3 search and sort - looked at all possible online forums but I cannot solve it. Please help. Where am I going wrong? Is my binary search OK? What about my bubble sort? ...
Newtocode's user avatar
0 votes
1 answer
218 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 ...
jayfeather31's user avatar
0 votes
1 answer
257 views

pset3: The sort function does not return my code

I am stuck with the implementation of the sort function. I have written a code, but I can't check if the code is correct. This is what I have done thus far: void sort(int values[], int n) { for (int ...
Max's user avatar
  • 11
0 votes
0 answers
123 views

pset3. question on sort in find.c

Why do I need to implement sort for find.c if by the task I should be only using linear search which just compares each value from 0 to maximum? What is the reason for the sort? Thank you.
ruthless_g's user avatar
0 votes
0 answers
88 views

search binary search

This code does not work. I tried everything. My sort function is working (I tested it with linear search, so it's fine). I am getting "Did not find haystack" even when the value is there. bool search(...
abc2015's user avatar
  • 15
0 votes
1 answer
269 views

Sort is not working on Pset3

After many hours can't figure out why the sorting and searching is not working... When running tests it I always get "Didn't find needle in haystack" whether the value is in or not in the array... ...
Robert R.'s user avatar
0 votes
3 answers
349 views

I can't check sort in Helpers.c

After reading the other questions, I still don't get how to check it. I tried to use gdb on ./find, but while I ran it, I could only see what was expected. Then, while typing n, it said "in fileops.c"...
BooFluff's user avatar