Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
4
votes
0answers
299 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 ...
8
votes
4answers
10k views

C++ vectors sort ascending/descending

How can I eliminate repetition from this code? ...
1
vote
2answers
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 ...
6
votes
3answers
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" ...
15
votes
4answers
8k 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 ...
4
votes
1answer
595 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? ...
6
votes
1answer
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 ...
3
votes
2answers
1k views

Mergesort implementation in Clojure

...
5
votes
1answer
7k 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 ...
9
votes
1answer
4k views

Merge sort in Scala

I've implemented merge sort in Scala: ...
2
votes
1answer
2k views

Sorting parallel ArrayList

I have a model class that contains 3 ArrayList which are in order by parallel of the same size. ...
1
vote
1answer
294 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 ...
1
vote
4answers
456 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 ...
4
votes
3answers
8k views

Sort List By Boolean

I have a class called Task that contain a member boolean variable Completed. I created a list of ...
17
votes
7answers
137k 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 ...
4
votes
1answer
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? ...
7
votes
3answers
757 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? <...
3
votes
2answers
527 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 ...
4
votes
1answer
1k 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: ...
6
votes
3answers
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 ...
26
votes
1answer
2k views

Merge sort in Scheme

...
4
votes
1answer
358 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 ...
9
votes
3answers
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 ...
3
votes
3answers
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: ...
3
votes
2answers
1k 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 ...
1
vote
4answers
282 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 ...
5
votes
2answers
10k 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). ...
8
votes
3answers
1k 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 ...
4
votes
2answers
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 ...
5
votes
4answers
13k 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. ...
2
votes
1answer
848 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 ...
5
votes
1answer
792 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 ...
7
votes
2answers
33k 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. ...
12
votes
2answers
5k views

Parallel Quicksort

As my parallel mergesort implementation was very memory dependent, I wanted to write a parallel quicksort one. Here it comes: ...
5
votes
2answers
122 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? ...
14
votes
2answers
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 ...
3
votes
4answers
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, ...
3
votes
1answer
477 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 ...
8
votes
3answers
1k views

Quick Sort Implementation

I have written the below code for quick sort in Java: ...
8
votes
4answers
794 views

Quicksort in C++

Here is the implementation I ended up with. Please post your feedback! ...
6
votes
2answers
452 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 ...
4
votes
2answers
268 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)...
15
votes
2answers
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? ...
7
votes
4answers
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. ...
8
votes
3answers
42k 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 ...
26
votes
5answers
79k views

Java Implementation of Quick Sort

This is my implementation of quicksort (algorithm taken from Cormen book). This is an in place implementation. Please let us know issues with this or any ideas to make it better. It performs at logN. ...
4
votes
4answers
722 views

My own quicksort algorithm

I will make it more reader friendly after I get the algorithm completed. Does anything with the quick sort algorithm stand out as for why it is not working 100%? This is not homework; I am just ...
4
votes
6answers
2k views

Listing books by priority

...
6
votes
3answers
540 views

Khan inspired Insertion Sort

I just watched a Khan Academy video on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program: ...
8
votes
2answers
1k views

Using bucket sort to rank students based on their marks

Problem: n students have marks and names. Rank students based on their marks and print their names. ...