Sorting is the process of applying some order to a collection of items.

learn more… | top users | synonyms

3
votes
2answers
45 views

Performance of Median routine using min performs abysmally

I am writing a routine to calculate median using the minimum of the numbers and then changing the value of the minimum to a large value outside the range of numbers (assuming you know the nature of ...
6
votes
3answers
330 views

Bubble sort algorithm in JavaScript

I'm new to JavaScript (and programming) and taking a course. I was tasked with creating a bubble sort on any array using JavaScript. Of course, since this is an algorithm challenge, no sort method ...
0
votes
0answers
19 views

Sorting ArrayLists [on hold]

I'm getting this error: The operator < is undefined for the argument type(s) java.util.ArrayList<FacebookUser>, java.util.ArrayList<FacebookUser> ...
1
vote
1answer
45 views

Natural mergesort

This is a problem from Robert Sedgwick's Algorithms book: Write a version of bottom-up mergesort that takes advantage of order in the array by proceeding as follows each time it needs to find two ...
2
votes
0answers
64 views

Nuts and bolts algorithm

I am trying to learn golang. This is a problem from Robert Sedgewick's Algorithm's book: You have a mixed pile of N nuts and N bolts and need to quickly find the corresponding pairs of nuts ...
0
votes
0answers
17 views

sortArray implementation [closed]

I created this program called sortArray, (pretty self evident what it should do). And, I got rid of all the syntactic errors, but, I know there some semantic ...
8
votes
4answers
776 views

Simple comparison of sorting algorithms in C++

I know this has been done a million times before, but this is my implementation of bubble-sort, insertion-sort, merge-sort, heap-sort, and quicksort. Any feedback on how to make it better would be ...
1
vote
1answer
35 views

Parallel natural merge sort

Continuing working on Natural merge sort, I have parallelized it. Requires \$\Theta(N)\$ space and runs in $$\Omega(N + \frac{N}{P}) \cap \mathcal{O}(N + \frac{N}{P}\log_2\frac{N}{P})$$ time, where ...
2
votes
0answers
18 views

Natural merge sort - follow-up

The previous iteration at Natural merge sort Now my code relies on C++14 and looks like: natural_merge_sort.h: ...
3
votes
3answers
60 views

Natural merge sort

Note: the next iteration at Natural merge sort - follow-up I have compiled natural merge sort algorithm from Java to C++. Natural merge sort sacrifices at most \$2N\$ amount of work in order to ...
2
votes
2answers
59 views

Use Selection Sort to Sort Employee Data About Pay

This program is supposed to prompt the user for hours and wage of 4 employees. Then the program will use a selection sort to sort the data into ascending value using the wages. The information like ...
1
vote
1answer
55 views

Is this the best way to check sorting (in recursion) without loops?

Please let me know if there is a shorter way to do it again without any kind of loops. Recursion only. ...
7
votes
1answer
161 views

Is this implementation of Quicksort good?

For fun, I decided to implement the quickest Quicksort I could. This is what I came up with. How can I make it better? I know that it's slower for sorted and already reversed lists (through testing), ...
1
vote
2answers
61 views

Possible sub-optimal selection sort

Why is this code "bad"? In all of the selection sort codes I am learning from, they do it much differently. I will learn the proper code from the book, but I would love to know why this particular ...
1
vote
1answer
33 views

Selection sort implementation in Java

Here's an implementation of selection sort, that sorts an array in ascending order. Please let me know of any improvements/optimisations that can be done. ...
1
vote
0answers
21 views

Insertion sort in Java

I've written a stable implementation of insertion sort, that sorts an array in ascending order. Please let me know of any improvements/optimisations that can be made. ...
3
votes
1answer
78 views

Custom iComparer

I've got a base class GraphUIControl which is inherited by 4 child classes: BubbleGraphUIControl ...
6
votes
1answer
75 views

Asc and desc array sort methods

I've used the typical INT array sort function found all over the internet for years, but I've also had a need to sort other items in an array, or even to just simple take an ...
3
votes
1answer
166 views

Sorting thousands of records

I have the following list to sort: A 0.53 B 0.56 C 0.56 D 0.98 E 0.33 Please note that my list may contains thousands of such type of records. I am sorting my ...
3
votes
1answer
63 views

Sort a linked list with merge sort in C

This is my version of a linked list in C. The function mergeSort requires a reference to the first and to the last nodes, as well as the indices of the first and ...
0
votes
0answers
29 views

Sorting products by name or price

Lets preface this by saying that when it comes to javascript, I am a hack. I make what I need happen by cobbling together crappy, inefficient, redundant code. I want to get better. Recently I was ...
4
votes
1answer
59 views

Union of intervals

I am trying to solve for the problem with a bunch of intervals: (1,2),(2,5),(4,7),(9,11) I find their union, which in the above given case would be: ...
4
votes
3answers
955 views

Array Sorting in C++

I have this simple implementation for array sorting: ...
5
votes
1answer
39 views

Update on Weave Merging n lists into single list

This is a follow up to my previous post from 7 months ago. I changed up the algorithm a little. Instead of inserting items into a new list, each item's final place is calculated up front. Sort of like ...
5
votes
1answer
50 views

Sort a stack in ascending order

Sort a stack in ascending order. You may only use one additional stack to hold items. Any comments on my solution? Worst case complexities: Memory complexity: O(n) Runtime complexity: O(n^2) Also, ...
3
votes
1answer
33 views

TurboSort challenge

I recently started to do some of the exercises in CodeChef and I did the TurboSort challenge here is it's description. It works fine with smaller arrays but can't pass some of the tests due to the ...
0
votes
1answer
49 views

log(n) “sort by value” Map<K, V>?

I've read so much arguing about "sort by value maps". Well, I wrote the following log(n) sort by value Map . And, by the way, a real Map , does not allow duplicate keys. Many of the maps I googled ...
2
votes
0answers
50 views

Classic sorting algorithms [closed]

I implemented the classic Sorting Algs in JS for practice. I come from a C++/Java background. Just wanted to make sure I didn't miss anything or if there was a 'better' JS way of doing it. Also, I ...
5
votes
3answers
123 views

Shuffle a sorted array so that left portions contains even indices and right portion contains odd indices numbers

I have been solving the following problem: Input array: \$[7,4,2,5,1,9,6]\$ Output array: \$[1,4,6,9,7,5,2]\$ I tried to do it in the following way: Sort the array. So, Input array becomes ...
2
votes
3answers
97 views

Sorting movie search results

I want to sort "movie search results" to get most probable movie that match "search". Input example: CARS.2.2011.720P.AC3.mkv I have a NameMatcher class ...
0
votes
3answers
40 views

Shorten a custom JS sort function

I have a sort function that needed to sort in a certain way. That position was sorted by mobile-top first, then empty position followed by mobile-bottom. Then on these I needed to sort by their ...
2
votes
2answers
47 views

Improving performance while sorting a JavaScript Object

I am sorting an array (filtered) containing JS-Objects by their attribute sortdist: ...
10
votes
2answers
55 views

Frequency counter utility class

Some very common tasks that keep popping up from time time: Find the most frequent something in a collection of things ... or the count of that thing ... or both (the item and its count) Get the ...
3
votes
1answer
63 views

Quick sort in PHP

Does this code show proper implementation of quick sort algorithm? If not, why? Can this code further be improved? ...
5
votes
1answer
72 views

Adding ranks to objects in an array

This works, and I personally find it elegant and kind of "neat," but then I worry it's a bit too tricky. Comments welcome: ...
1
vote
2answers
70 views

Bubble sort in PHP

Does this code show proper implementation of bubble sort algorithm? If not, why? Can this code further be improved? ...
1
vote
4answers
53 views

Finding the second largest element of large input sets

I have a problem where I need to find the second maximum element of the user inputs. It's an online practice problem and I can't figure out why the server responds back with a Non-Zero Exit Code error ...
2
votes
1answer
108 views

Bucket sort implementation

I want to optimize my code for performance and fine-tuned logic. ...
3
votes
0answers
92 views

Building an efficient bubble sort function

I've been asked to create a bubble sort function that checks whether the array has been filled sorted before all passes are complete, thereby avoiding unnecessary passes. This is to involve ...
4
votes
3answers
150 views

Merge sort implementation and improvements

I would like your opinion on my Java implementation of the merge sort algorithm on an integer array, since I'm not really into algorithms I'd like to know from you if this is a correct implementation ...
1
vote
1answer
43 views

Add sorting to a namedtuple

I currently override the sorting methods provided by namedtuple by doing something like this: ...
2
votes
0answers
148 views

Directed Acyclic Graph with topological sort

I have here a class which represents a directed acyclic graph (Graph) and a vertex in the graph (Vertex). The vertices are ...
2
votes
0answers
44 views

Search/sort/create functionality, implements bubblesort and sequential search

I've moved my main() to the bottom of the code block in order to fit it all in one class for this submission. If there is a better way to do it? ...
3
votes
2answers
152 views

Radix sort with integer divisions

Here's a perhaps naive but simple implementation of Radix sort in Java. It works with any radix, and both positive and negative numbers. ...
0
votes
1answer
78 views

Generic list heapsort in Java

This is an implementation of heapsort as seen on Programming Pearls, adapted for java List collections. It is working on a copy of the list passed-in on purpose at the moment. ...
4
votes
0answers
40 views

Quicksort in SAS for sorting datasets

As a challenge for my own amusement, I decided to write a SAS macro for sorting datasets, deliberately avoiding all of the built-in methods (e.g. proc sort / ...
1
vote
1answer
70 views

Sort by a custom date field

I've got this code to work, but being really new to PHP, I don't know if this is proper. I've sorted a CPT loop by a custom date. I'm displaying items from most recent (or future date) to oldest if ...
3
votes
2answers
104 views

Recursive functions for sorting

I made a few recursive functions for learning purposes which do a variety of tasks. Here is my current and functioning code: ...
3
votes
2answers
74 views

Sort ArrayList in a better way

I have a list of categories (in this example I used String but in my project I have a model) which must be sorted like this: on top we should have 2 categories ...