Questions tagged [sort]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
136 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 ...
0
votes
1answer
126 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 ...
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
128 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 ...
0
votes
1answer
228 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+...
0
votes
1answer
853 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 ...
0
votes
1answer
217 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 ...
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
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 { ...
1
vote
1answer
18 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'...
0
votes
1answer
139 views

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

string book[] = { "Chen", "Kernighan", "Leitner", "Lewis", "Malan", "Muller", "Seltzer", "Shieber", "Smith" } int main(...
0
votes
1answer
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 ...
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
191 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 ...
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
58 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> ...
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
2answers
239 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] < ...
0
votes
1answer
514 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 ...
0
votes
2answers
42 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. /** * ...
0
votes
1answer
53 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[] ...
0
votes
1answer
38 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 ...
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
132 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
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) {// ...
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 ...
1
vote
1answer
71 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 ...
0
votes
1answer
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=...
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
2answers
78 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)....
0
votes
1answer
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]; ...
0
votes
1answer
145 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 ...
0
votes
1answer
363 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 ...
0
votes
1answer
64 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] == ...
1
vote
1answer
2k 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 ...
0
votes
1answer
50 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 ...
0
votes
1answer
110 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
2answers
68 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:...
0
votes
2answers
722 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[], ...
0
votes
1answer
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 ...
0
votes
1answer
194 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) ...
0
votes
1answer
99 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; ...
0
votes
1answer
378 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) ...
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
1answer
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 ...
0
votes
1answer
112 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 ...
0
votes
1answer
162 views

Why doesn't my sort algorithm work

//Example program #1 from Chapter 25 of Absolute Beginner's Guide //to C, 3rd Edition //File Chapter25ex1.c /*This program declares and initializes an arrays of character pointers and then asks for ...
0
votes
1answer
764 views

Pset3 Segmentation Fault

Where is the segmentation fault occurring in this program? Thanks! /** * helpers.c * * Computer Science 50 * Problem Set 3 * * Helper functions for Problem Set 3. */ #include <cs50.h> #...