Questions tagged [sorting]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
3answers
80 views

Does our implementation of speller need to be able to handle an unsorted input dictionary?

In another post, user1723 touched on a question I had while watching the lecture, sections, and walkthrough on pset6. The question was, why would we need to sort our linked lists, when dictionaries, ...
1
vote
1answer
105 views

Accessing const int MAX value from helpers.c

I am trying to implement the hacker3 sorting algorithm. The one that requires a O(n). I think I have figured out the algorithm but I won't spoil it by posting any code here. My question is regarding ...
1
vote
1answer
84 views

pset3 move() makes every tile swapped a blank tile

I rewrote almost the entire code and I finally was able to make the tiles swap. Problem is at every swap the blank tile gets duplicated and the tile swapped disappears, eventually rendering a Segfault....
0
votes
2answers
678 views

What's wrong with this binary search implemented using recursion?

This is pset3 and I've tried making it work for numerous hours. It always returns false whether the 'needle' is found in the 'haystack' of arrays or not. When typing this in the command window: ./...
0
votes
1answer
27 views

Week 2 Merge Sort: Why is it assumed that the elements will be in order when they are merged?

When using the Merge Sort algorithm, I feel like everything makes sense until we start "merging" the elements back together. Why is it assumed implicitly that the process of merging will put the ...
0
votes
1answer
19 views

Selection Sort: Holes in Logic

#include <cs50.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { string s = get_string("Enter a number: "); string answer ...
0
votes
1answer
182 views

Pset3: Tideman - Sort_pairs function

I am trying to solve sort_pairs by including a property - int winsize - into the struct of pair. The new pair struct is: typedef struct { int winner; int loser; int winsize; } pair; I ...
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
2answers
68 views

Why are the sorted numbers not being printed out?

I'm trying to sort and print out the results, but it is showing nothing. I'm sure my implementation of bubble sort is correct. Where do you think is the error? I also modified the helpers.h to ...
0
votes
1answer
29 views

How to search in effective manner?

As in Lecture video of finding a name in telephone directory we get to half and choose one half where we can find the name. But my question is when the names are random how to effectively find a name. ...
0
votes
2answers
289 views

CS50x 2020 Problem Set 3 Tideman

I have been working on the Tideman problem for a while now, and am still not able to find out how to implement the sort_pairs() function. I have implemented my sort_pairs() function, but it is not ...
0
votes
1answer
51 views

Sorting a List Based on Stock Symbols in CS50x2017 Problem Set 7 Index

Would this be the way to sort a list of stock information with sorted using stock symbols as the key to sort on? new_translactions_info = sorted(transactions_info, key=lambda transactions_info: i....
0
votes
1answer
53 views

Pset3 segmentation error

I am having trouble with segmentation error with sorting code. I have tried to understand how I am accessing something that is out of boundaries, but so far no ideas. It runs smoothly in cases where ...