Questions tagged [sorting]

Use this tag when arranging items in order is the main focus of the code.

Filter by
Sorted by
Tagged with
1 vote
2 answers
3k views

Suggestions on improving Sorting Algorithm (Progress ABL/4GL)

I have written some sort routines for PROGRESS 4GL/ABL and wanting to get some input whether these sorts can be improved. And whether my sorts are true to name. And I would also be very interested in ...
AquaAlex's user avatar
  • 151
1 vote
1 answer
2k views

Lamba sorting for results

I have the List method that takes sorting parameter to sort results. The sorting parameter value is the same as the column name. ...
Expert wanna be's user avatar
4 votes
1 answer
6k views

Quicksort using pointers

As an exercise, I've written quicksort algorithm in C using pointers. Please comment and help me find the cases where it breaks (if any). ...
ShuklaSannidhya's user avatar
4 votes
0 answers
313 views

Quick Insert Merge Sort

I have written this code to sort a list of numbers, in increasing order. It is a combination of quick sort, insertion sort, and merge sort. I make the first element of the list a pivot, then I go ...
Rajesh Bhat's user avatar
8 votes
4 answers
10k views

C++ vectors sort ascending/descending

How can I eliminate repetition from this code? ...
Felix Dombek's user avatar
  • 1,081
1 vote
2 answers
1k views

Quicksort in Ruby!

I've been teaching myself Ruby this weekend. First of all, I am aware that there is a built-in sort function. I've written this code strictly as an exercise. I have background primarily in C# and ...
Vivian River's user avatar
6 votes
3 answers
2k views

Sorting random non-repeating numbers

I am working on a program in which 10000 random non-repeating numbers are selectively sorted into ascending order" ...
Fernando Martinez's user avatar
15 votes
4 answers
9k views

Sorting 10,000 unique randomly-generated numbers

I have to write this program in java. Write a program name sorting.java that will use an array to store 10,000 randomly generated numbers (ranging from 1 to 10,000 no repeat number). Here is what ...
Fernando Martinez's user avatar
3 votes
1 answer
635 views

Am I using C++11 features like STL and move semantics correctly?

I've implemented selection sort, heap sort, insertion sort, and iterative quicksort using C++11. Am I using the correct STL data structures/algorithms? Am I using move semantics correctly in my code? ...
masrtis's user avatar
  • 193
6 votes
1 answer
5k views

Stable radix sort in-place using O(1) space

I am trying to implement a stable radix sort in place with O(1) space. I've seen Wikipedia, and I notice the C implementation is using a temporary variable to hold the sorted value for each pass, and ...
bysreg's user avatar
  • 163
3 votes
2 answers
2k views

Mergesort implementation in Clojure

...
Bruno Kim's user avatar
  • 133
7 votes
1 answer
8k views

Multi-threaded sort

I wanted to write a multi-threaded sort, but unfortunately I don't know much about threads, especially in C++11. I managed to make something work, but I would be highly surprised if it was the best ...
Simon-Okp's user avatar
  • 173
9 votes
1 answer
5k views

Merge sort in Scala

I've implemented merge sort in Scala: ...
chris's user avatar
  • 415
2 votes
1 answer
2k views

Sorting parallel ArrayList

I have a model class that contains 3 ArrayList which are in order by parallel of the same size. ...
wtsang02's user avatar
  • 177
1 vote
1 answer
317 views

Displaying plotted data in serpentine order

I have to display some set of: Data in serpentine order. In an experiment there are replication, range, and plot. Replications contains range a plot. A range contains a plot. If there are 2 ...
VIckyb's user avatar
  • 665
1 vote
5 answers
493 views

Sorting an array of jobs by various criteria

Below is my current code for sorting an array, "$jobs_list". It's not very DRY and it's fugly. And there are several more similar case statements still to go in. How could I write it so my brain ...
user avatar
4 votes
3 answers
10k views

Sort List By Boolean

I have a class called Task that contain a member boolean variable Completed. I created a list of ...
Rhs's user avatar
  • 548
17 votes
7 answers
143k views

Finding repeating numbers in an array

I want to search through an array of n numbers and find the numbers that are repeated. So far I have this code, which does the job, but I find it to be a rather cumbersome method, but I can't seem to ...
Hatori Sanso's user avatar
4 votes
1 answer
2k views

Sorting file lines in natural order

I'm new to Java and have been through some tutorials and I'm in the next step of checking how I'm doing now. Is there a better way of doing this? ...
Java Noob's user avatar
8 votes
3 answers
768 views

Is this attempt at a merge sort correct?

I am trying to write a merge sort algorithm. I can't tell if this is actually a canonical merge sort. If I knew how to calculate the runtime I would give that a go. Does anyone have any pointers? <...
Beatrice's user avatar
3 votes
2 answers
536 views

creating a hash based sorting algorithm

For experimental and learning purposes. I was trying to create a sorting algorithm from a hash function that gives a value biased on alphabetical sequence of the string, it then would ideally place it ...
user avatar
4 votes
1 answer
2k views

Sorting numeric <LI> tags without omitting the attributes

I used the following Javascript to sort an unnumbered list of numeric li-tags as follows: ...
Wim's user avatar
  • 257
6 votes
3 answers
8k views

My version of C++ quicksort

I built my code according to the algorithm provided in this YouTube video. Please review it and help me find any problems. It definitely takes a lot longer than the ...
Shane Hsu's user avatar
  • 265
2 votes
2 answers
2k views

Search script for autocomplete suggestions

The following search script creates a JSON response for an autocomplete field. The tables and fields search from are flexible to allow using the same script for different type of searches - the idea ...
kontur's user avatar
  • 123
26 votes
1 answer
3k views

Merge sort in Scheme

...
C. K. Young's user avatar
  • 2,342
4 votes
1 answer
415 views

Three implementations of mergesort in F#

I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage? First solution ...
nicolas's user avatar
  • 171
9 votes
3 answers
5k views

Multi-tiered sorting using custom IComparer

I have this custom IComparer I use to sort a list of SurveyResponse objects, but it seems really inefficient, both in terms of ...
mo.'s user avatar
  • 245
3 votes
3 answers
3k views

Finding the highest values a and b from an array

I struggled a short while to make this work, so I'm wondering if there are any smarter ways for finding the highest of two values per array element? Uh, hard to explain by words, but by code its easy: ...
Rookie's user avatar
  • 31
3 votes
2 answers
2k views

Bubble sort implementation with tests

For practice I tried implementing a bubble sort algorithm in Ruby. I'm especially interested in creating clean DRY and KISS code and keeping things readable, but efficient. Any hints to improve things ...
bartaelterman's user avatar
1 vote
4 answers
291 views

Insertion vs Selection

I currently have a selection sorting algorithm, but need some help turning it into a insertion sort, I understand a insertion sort if faster? The hand array is full, and it needs to sort from lowest ...
user1051043's user avatar
5 votes
2 answers
12k views

Sorting a list of numbers in increasing order

Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function). ...
Rajesh Bhat's user avatar
8 votes
3 answers
2k views

Reorder a list of courses, given their prerequisites

I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the ...
user1331369's user avatar
4 votes
2 answers
2k views

Merge sort on an Integer class

This is a specific case in merge sort. I'm trying to do a merge sort on an array that's created using the Java Integer class. My implementation is slow and ...
SharkTiles's user avatar
5 votes
4 answers
14k views

Groovy: find all elements in a list equal to the max element

Is there any simpler way to find all elements in a list that are equal to the max element. ...
T.Dabrowski's user avatar
2 votes
1 answer
1k views

C++: Data sorting taking a long time

I wrote a simple program that takes the enable1.txt word list of scrabble/words with friends and searches it for an input. In order to search the massive list of ...
Casey's user avatar
  • 748
5 votes
1 answer
833 views

Jon Bentley's bitmap sort implementation

I've implemented Jon Bentley's bitmap sorting algorithm from Column 1 of his Programming Pearls book. This code supports user-defined integer range (works from ...
Artur Galiullin's user avatar
7 votes
2 answers
34k views

Insert sort on a linked list

I want to do insert sort in a linked list without using dummy nodes. This is my code. How can this be improved? Any input is appreciated. ...
user384706's user avatar
12 votes
2 answers
5k views

Parallel Quicksort

As my parallel mergesort implementation was very memory dependent, I wanted to write a parallel quicksort one. Here it comes: ...
inf's user avatar
  • 564
5 votes
2 answers
125 views

Ranking lines of a file according to number of occurrences

I recently dived into Ruby, so I want to improve this code. Is this good enough? ...
Premist's user avatar
  • 53
14 votes
2 answers
8k views

Parallel Merge Sort

Parallism is achieved by using a simple call to tbb::parallel_invoke(). However I can't break a speedup factor of x2 (after ~3-4 parallel HW threads), although 8 ...
inf's user avatar
  • 564
3 votes
4 answers
2k views

Shifting records in SQL Database while sorting with algorithm

I have a table in a SQL Server database, which holds information of some images, and the relevant gallery of them. The columns are like: ImageId, ...
Saeed Neamati's user avatar
3 votes
1 answer
492 views

JavaScript shuffle idea

Based on the standard implementation of Array.sort in JavaScript, would the following be a reasonable way of shuffling the contents of an array? Is it moderately ...
ForbesLindesay's user avatar
8 votes
3 answers
1k views

Quick Sort Implementation

I have written the below code for quick sort in Java: ...
aj123's user avatar
  • 81
8 votes
4 answers
834 views

Quicksort in C++

Here is the implementation I ended up with. Please post your feedback! ...
Nils's user avatar
  • 474
6 votes
2 answers
483 views

Sorted grep in Haskell

This program implements a sorted grep, that is, a specialized version of grep for sorted files. It uses binary search for the lines of a file that begin with a ...
lbolla's user avatar
  • 388
4 votes
2 answers
287 views

Optimizing error-sorting method

I just made this sort method. It runs fine and the code looks okay in my eyes. Is is possible to optimize it so it runs faster? If it's \$O(n^3)\$ now, it would be interesting changing it to \$O(n^2)...
radbyx's user avatar
  • 143
15 votes
2 answers
1k views

Is this C++ quicksort program okay?

I wrote a quicksort program in C++. Is it okay to implement it this way? Am I using pointers correctly? Is my style okay? Any ideas to speed it up or save memory? ...
Kolt's user avatar
  • 253
7 votes
4 answers
3k views

Heapsort is not modular

For the time being, I am not interested in any recursive solution. The code is not modularized; the whole body is inside the main function. ...
0 votes
3 answers
1k views

Sort an array of sentences alphabetically, ignoring the first word if it equals 'the' (case insensitive)

...
Mild Fuzz's user avatar
  • 143
8 votes
3 answers
43k views

Sorting algorithms implemented in C++

Implemented Bubble Sort, Insertion Sort, Selection Sort, Quick Sort, Merge Sort and Radix Sort https://code.google.com/p/medicine-cpp/source/browse/trunk/cpp/sorting/SortingAlgorithms.cpp ...
Medicine's user avatar
  • 443