Questions tagged [sort]

The tag has no usage guidance.

17 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
1answer
558 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 ...
0
votes
0answers
48 views

cs50x tideman sort not work

// Sort pairs in decreasing order by strength of victory void sort_pairs(void) { // TODO printf("=-------------------------- sort---------------pair=%d\n",pair_count); pair pairx[...
0
votes
1answer
32 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 ...
0
votes
1answer
44 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' ...
0
votes
1answer
35 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) { ...
0
votes
1answer
23 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: ...
0
votes
1answer
48 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 ...
0
votes
1answer
130 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 ...
0
votes
2answers
104 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 ...
0
votes
1answer
57 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 ...
0
votes
1answer
524 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? ...
0
votes
1answer
109 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 ...
0
votes
1answer
233 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 ...
0
votes
0answers
121 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.
0
votes
0answers
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(...
0
votes
1answer
201 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... ...
0
votes
3answers
342 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"...