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

learn more… | top users | synonyms

-1
votes
0answers
17 views

how to set bucket sort to sort negative numbers in c++ [on hold]

I just finished the bucket sort, it works fine without a for function: ...
3
votes
1answer
45 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
53 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
47 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
44 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
50 views

Bucket sort implementation

I want to optimize my code for performance and fine-tuned logic. ...
3
votes
0answers
68 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
96 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
32 views

Add sorting to a namedtuple

I currently override the sorting methods provided by namedtuple by doing something like this: ...
2
votes
0answers
22 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
28 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
64 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
45 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
20 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 / ...
3
votes
2answers
96 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
59 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 ...
0
votes
1answer
31 views

Natural sorting/comparing algorithm in TypeScript

This code sorts string that may contain numbers in natural order, that's it, "item 2" comes before than "item 10". It currently ignores case. I plan to implement options to handle case sensitivity and ...
1
vote
0answers
27 views

Binary heap implementation in Golang

I have implemented a binary heap in Go to get familiar with the language. GitHub ...
8
votes
2answers
201 views

Efficiently create and sort a Collection

The goal of my code is to sort data into two categories. It must use a local copy of the initial data from Collar (Top View).csv. My code creates a Collection of items called Collars using the initial ...
3
votes
2answers
85 views

Merge Sort Implementation: Space Usage

I have made a merge sort algorithm but am unsure of the 'Space Usage' of the algorithm. ...
10
votes
7answers
1k views

Merge sort for a List<T>

Is this merge sort following good coding standards? What are some improvements I can make to make it cleaner? ...
4
votes
4answers
181 views

Quick Sort - implementation

Can anything be improved in this code? ...
4
votes
3answers
53 views

Displaying sorted results of a web crawl

The issue I have with this class is that most of the methods are almost the same. I would like for this code to be more pythonic. Note: I plan on replacing all the ...
2
votes
1answer
51 views

Collection of sorting types

A collection of sorting types as following insertion, radix, selection and heap sorts. How can i improve it? ...
33
votes
12answers
3k views

Efficiently squaring each element in a sorted array, keeping it sorted

The other day I was asked the following question during an interview: Given a sorted array, how would you square each element of this array, while keeping it sorted? I froze up and wrote a ...
0
votes
0answers
59 views

Recursive partition sort is inefficient

I have written a recursive method for a partition sort that sorts the array. However, when I use an array of more than 10-20 elements the program takes a really long time to complete. (On my computer ...
1
vote
2answers
57 views

Sort and display input numbers

How do I decrease time, especially in sorting? Given a list of numbers, you are to sort them in non-decreasing order. Input t – the number of numbers ...
2
votes
1answer
63 views

In-place quicksort algorithm in Python 2

I have tried to implement an in-place quicksort Algorithm in Python 2. Please suggest how I can Make the code more efficient Increase readability Improve writing style Make it more Pythonic ...
4
votes
2answers
75 views

Subsorting with multiple Comparators

I've seen a number of questions on Stack Overflow of the kind of "How do I sort on fields X AND Y?" The most common answers to those questions consists of "Write a custom Comparator." But what if you ...
4
votes
1answer
44 views

Test many sorting algorithms using Python and Nose

I'm trying to learn how to build a good test suite, using simple sorting as an example. Particularly, I am using Nose to generate all the tests based on a simple list of lists, where each sublist is a ...
3
votes
3answers
128 views

Radix sort with C++

At first the input array is traversed and for each number the lsb is found. Then the number is put into appropriate bucket according to it. For example for an input array { 123, 45}, at first 123 will ...
3
votes
0answers
55 views

Parallel MSD radix sort in Java

I have this parallel implementation of MSD radix sort, which processes the entries by one particular byte. At each byte index, it has three phases: Count the bucket sizes. Insert each entry to its ...
1
vote
0answers
28 views

MSD radix sort in Java for parallel arrays - follow-up 2

The previous and second iteration at: MSD radix sort in Java for parallel arrays - follow-up Changes: arrays[j][i] != arrays[j + 1][i] to ...
4
votes
1answer
98 views

MSD radix sort in Java for parallel arrays - follow-up

The previous and initial iteration at MSD radix sort in Java for parallel arrays. Changes: Entry hides both the sort key and satellite datum in private final ...
1
vote
0answers
102 views

Object counting sort in Java

The counting sort for integers counts the amount of each integer, then traverses the count entries in order, and for each entry inserts the integer representing the bucket into the array as many times ...
7
votes
1answer
118 views

Stable Sort in C#

I wrote a stable sort algorithm in C#. It is just a simple iteration, and is probably not very optimal: ...
3
votes
1answer
74 views

3-way merge sort in Java

All those numerous merge sorts split the range in two halves. This is a modification that splits each range into 3 subranges. My demo suggests that 3-way merge sort is pretty efficient on large ...
0
votes
0answers
49 views

A different implementation of Heap Sort

The following implementation is a bit different form the standard implementations I have read. Is it correct? ...
5
votes
1answer
70 views

Reverse Groups challenge at CodeEval.com

I am working through challenges at CodeEval.com and wanted to get your input on my code for this challenge. Given a list of numbers and a positive integer k, reverse the elements of the list, k ...
2
votes
4answers
98 views

Is it correct to use Java Comparator with 3 conditions at the same time?

I am trying to create a class whcih implements Comparator class. The thing is that I have a list with some objects. This object is composed of 3 fields (Strings). My purpose is to sort the list ...
2
votes
1answer
64 views

MSD radix sort in Java for parallel arrays

I have this MSD (most-significant digit) radix sort sorting Entry objects holding a sorting key of type long and a satellite ...
4
votes
1answer
49 views

'Sort By' Function for Rebol

I'm looking for a more consise way to sort a block of objects. Where you can sort a block of blocks based on the numeric position of the values to compare, there's no such shorthand for comparing ...
1
vote
0answers
74 views

Optimizing insertion sort for small amounts of data

I'm building a hybrid sort, and for that I need a fast and adaptive sort ideal for small sizes (< 65 elements). Insertion sort immediately comes to mind, and I've been tinkering with different ...
11
votes
2answers
132 views

Allowing the user to alphabetize or randomize the contents of a text file

As a newbie programmer, I decided to try my hand at making a program whose function actually might be useful to someone, somewhere. This utility takes a text file, reads it out to the user, displays ...
1
vote
0answers
77 views

Radix sort (LSD) and counting sort

I'm reading CLRS, and to practice, I rolled my version of radix sort and counting sort. I was looking at some reference implementations, particularly the LSD one from rosetta code, and mine performs ...
1
vote
0answers
55 views

Elegant way to sort on multiple properties that might be undefined

I'm trying to sort an array with JavaScript. The objects should be sorted based on several properties (about 4 in my real scenario), which are all strings that may also be null or undefined. A null or ...
3
votes
2answers
145 views

Sorting by patients' name or birth

Is there a way to write this simpler? ...
-1
votes
2answers
87 views

Sorting array with respect to two properties

I'm sorting with respect to Width and Length. However, Width has the significance ...
5
votes
3answers
96 views

Could this QuickSort be made more consise and “nicer”?

After seeing this example of a "primitive" QS implementation in F# by Scott W ...
6
votes
2answers
213 views

Merge sort using sentinels

This is my implementation of recursive merge sort, using sentinels: ...