Questions tagged [sort]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
46 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 ...
user avatar
0 votes
1 answer
65 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 ...
user avatar
0 votes
1 answer
69 views

CS50 Tideman : Sort Pairs problem - check50 automatic test fails, but output seems correct

Good morning guys, I am working on implementation of tideman. Particulary at implementing sort_pairs function. I have written it and tested - and the output seems sorted in a proper way. However - ...
user avatar
0 votes
1 answer
248 views

Tideman sort_pairs function

I tested this sort function separately and it sorts alright, but somehow doesn't pass the check50 test. The pairs.strength is the winning strength, recorded previously in add_pairs function. All my ...
user avatar
  • 13
0 votes
1 answer
159 views

Pset3: Tideman sort_pairs doesn't work?

I know this has been asked before but I've checked every thread and couldn't find a solution. According to check50, my code for sort_pairs() doesn't work, and I can't figure out what could be wrong ...
user avatar
  • 13
0 votes
1 answer
195 views

Problem with plurality

when i check50 my code I get this message : :( print_winner identifies Bob as winner of election print_winner function did not print winner of election :( print_winner identifies Charlie as ...
user avatar
0 votes
1 answer
295 views

tideman pset3 sort pairs - code doesn't work

I know it's not efficient. But I don't know why it doesn't work...:( void sort_pairs(void) { pair sorted_pairs[pair_count]; int strength[pair_count]; for (int k = 0; k < pair_count; k+...
user avatar
  • 5
0 votes
1 answer
1k views

Pset3: Tideman sort_pairs not work

I have been trying to implement sort_pairs function using selection sort algorithm. After testing for every case, the sort_pairs is returning right answer but check50 is marking it as wrong. for (int ...
user avatar
0 votes
1 answer
274 views

check50 claiming pairs are sorted incorrectly

On Problem Set 3, check50 has flagged my program as not having sorted the pairs correctly. However, the pairs array appears to be sorted in every case I've tried. I used insertion sort and had ...
user avatar
0 votes
1 answer
51 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 ...
user avatar
  • 3
0 votes
1 answer
28 views

PSet3 helpers.c fails one of the checks

I'm working on the PSet3 Find problem. Here's my code for the sort and search functions: bool search(int value, int values[], int n) { if (value < 0) return false; else { ...
user avatar
  • 3
1 vote
1 answer
20 views

Find's sort: instructions vs code: O(n) or O

The docs for find's sort say, The running time of your implementation must be in O(n), where n is the array’s size. Yes, linear! Keep in mind that 65,536 is a constant. However, the code that we'...
user avatar
0 votes
1 answer
150 views

Purpose of sizeof(book)/sizeof(string) in lectures' binary sort?

string book[] = { "Chen", "Kernighan", "Leitner", "Lewis", "Malan", "Muller", "Seltzer", "Shieber", "Smith" } int main(...
user avatar
  • 144
0 votes
1 answer
41 views

Pset 3 -> Counting Sort - need tips to find my error

What is wrong in my code? Why am I getting a segmentation fault? void sort(int values[], int n) { int aux_list[65536] = {0}; //map the count of values in the values list as the index of the aux list ...
user avatar
0 votes
1 answer
50 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' ...
user avatar
  • 7
0 votes
1 answer
289 views

pset3 help with find, bubble-sort and search

I've been struggling for over a week with this and can't figure out how to get my program to pass check50. I'm getting very interesting mixed results from check50: :) helpers.c exists. :) helpers.c ...
user avatar
  • 7
0 votes
1 answer
39 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) { ...
user avatar
  • 1
0 votes
1 answer
63 views

Question about Bubble Sort

I actually try to get the hang of using bubble sort. So i did a little practice in a online code space with a 10 int array, but somehow it doesn´t work competely right yet. #include <stdio.h> ...
user avatar
0 votes
1 answer
24 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: ...
user avatar
  • 101
0 votes
2 answers
246 views

PSET3 find having trouble. Can someone help?

For some reason bubble sort is not working. Can someone help. binary search bool search (int target, int array[],int length) { int end = length-1; int start = 0; while (array[start] < ...
user avatar
0 votes
1 answer
613 views

CS50 Helpers.C Find Less, No Idea What's Going On

Final Code: /** * helpers.c * * Helper functions for Problem Set 3. */ #include <cs50.h> #include "helpers.h" /** * Returns true if value is in array of n values, else false. */ bool ...
user avatar
  • 115
0 votes
2 answers
43 views

PSET 3, there is nothing happening

My code is not working at all and I am not able to find a proper solution. UPDATE: So I just now came to know that I am not able to use ^d if needle is not found otherwise it is working. /** * ...
user avatar
  • 1
0 votes
1 answer
54 views

Segmentation fault for pset3 sorting

Can't seem to figure out this segmentation fault and what's causing it. My sorting algo works fine for 100 generated numbers, but at some point things start to go awry. I'm adding 1 to a counter[] ...
user avatar
0 votes
1 answer
43 views

Concept of run time in lecture week 3

In week 3's lecture, David talked about the concept of runtime where the worst possible scenario for say insertion sort is O(n squared) and the best case scenario would be omega(n). I dont understand ...
user avatar
  • 29
0 votes
1 answer
49 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 ...
user avatar
0 votes
1 answer
218 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 ...
user avatar
  • 3
0 votes
2 answers
111 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 ...
user avatar
0 votes
1 answer
126 views

pset3 helpers.c (help)

:( finds 42 in {39,40,41,42} \ expected an exit code of 0, not 1 ( it meaning I missing or have a return error??? ) bool search(int value, int values[], int n) {// ...
user avatar
0 votes
1 answer
60 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 ...
user avatar
1 vote
1 answer
76 views

pset3 find: seg fault (int array won't initialize to 0s)

Ok so I made what I believe is a counting sort. I first wrote it in Java just to test it, and it works there, but when I transferred it to CS50 IDE (of course, I modified it slightly to C syntax) it ...
user avatar
0 votes
1 answer
66 views

pset3 - find less / sort video availability

Is anyone else having issues with the sort video for pset3, under find, less comfortable? URL is: http://docs.cs50.net/problems/find/less/find.html, which points to: https://www.youtube.com/watch?v=...
user avatar
0 votes
1 answer
530 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? ...
user avatar
0 votes
2 answers
82 views

Pset3 - Find: I can't find what's wrong with my sorting algorithm...?

I have an issue with the "find" problem. When I test my program, it seems to get stuck in an infinite loop (nothing is prompted, there is just a blank space and I have to kill the program with ctrl c)....
user avatar
0 votes
1 answer
123 views

is this function correct? CS50 Pset3 (Find)

// TODO: implement an O(n^2) sorting algorithm int c,i,s; c = 0; for (i=0; i < n; i++) { if (values[i] > values[i + 1]) { s = values[i]; values[i] = values[i+1]; ...
user avatar
0 votes
1 answer
156 views

pset3: sort -- Selection Sort Implementation

I have been working away at my implementation of Insertion Sort for this problem set, and I've run into a predicament. I have gotten the sort function almost functional, however I'm sure we all know ...
user avatar
  • 3
0 votes
1 answer
541 views

pset3 binary search won't find values when at end of array

As the title says, the program doesn't pass the check when 42 is the last element of the array. I've seen a related post about this issue but it did not give me enough to fix the problem. The code is ...
user avatar
  • 2
0 votes
1 answer
73 views

binary search code showing segmentation fault

this is my code. bool search(int value, int values[], int n) { int max = n -1; int min = 0; int mid; while(n > 0) { mid = ((min = max)/2); if(values[mid] == ...
user avatar
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 ...
user avatar
0 votes
1 answer
58 views

Pset3 - my bubble sort breaks the find function

I have tried to code bubble sort as my sort function, but when I run find it no longer exits when using ctrl d and just gives me a blank terminal line. My code is below, i'd be grateful if someone ...
user avatar
0 votes
1 answer
184 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 ...
user avatar
0 votes
2 answers
71 views

is my swap function breaking my bubble sort implementation?

I'm trying to implement the bubble sort algorithm in pset3, but it's not working! Pretty sure it's because of failure to swap. Been working on it for a while, with no success. Here's the relevant code:...
user avatar
  • 11
0 votes
2 answers
760 views

Help with sorting function

I am trying to implement an insertion sort algorithm for pset3, but I believe the problem lies in how I swap the values at the end of the code. Any clues on how to fix this? void sort(int values[], ...
user avatar
0 votes
1 answer
45 views

Where is sort supposed to go?

I am working on pset3 at the moment and while all problem sets so far had their challanges this one got me a little lost! I implemented search into helpers.c. Now I am supposed to implement sort. But ...
user avatar
  • 104
0 votes
1 answer
197 views

sort algorithm is working, but i finding it hard to implement in helpers.c

#include <stdio.h> #include <cs50.h> int main(void) { int values[12] = {10,2,14,5,7,4,3,13,15,22,8,24}; int i = 0; int n = 12; for(int x = 0; x < n*n; x++) { while(i<n-1) ...
user avatar
0 votes
1 answer
100 views

CS50x helpers.c help with looping

void sort(int values[], int n) { int temp; int swapcounter = 1; while (swapcounter != 0) { for(int i = 0; i < n; i++) { swapcounter = 0; ...
user avatar
0 votes
1 answer
386 views

Pset 3 sort function won't swap

I've been going crazy about this, I watched week 4's lectures, search in here for similar problems, but it seems everyone got pass this step easily. Here's my code (I passed in numbers 5 4 3 2 1) ...
user avatar
0 votes
1 answer
252 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 ...
user avatar
  • 11
0 votes
0 answers
122 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.
user avatar
0 votes
1 answer
67 views

What's wrong with my sort function?

I can't figure this out, and its been driving me nuts. Can anyone help me see what I've done wrong? Headers are ommitted void sort(int values[], int n) { //TODO: implement an O(n^2) sorting ...
user avatar
  • 53
0 votes
1 answer
161 views

'redefinition of i' compilation error pset 3 sort

I started with a very simple for loop for my sorting algorithm, and don't know what this error means/cant see anything wrong with the code. I will post a screen shot of the error and an excerpt of the ...
user avatar
  • 4