Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
4
votes
2answers
511 views

Bottom-up singly linked list merge sort in C++

This is an implementation of a singly linked list merge sort I did on paper during a job interview recently, using a bottom-up approach. The requirement was simply "implement a merge sort for a ...
-1
votes
1answer
1k views

Sort multidimensional array based of the difference in the value

Sort multidimensional array based of the difference in the value, if value is same sort on first column. Constrains: No of rows can be any but fixed no of column ie 2. Example: <...
2
votes
1answer
94 views

Sorting with different Algorithms

I'm new to Go, so I implemented a few sorting algorithms for practice. For example, I have an in-place insertion sort, and a bubble sort: ...
6
votes
2answers
404 views

Bubble sort with counting swaps and comparsions

I have bubble sort code below, which has to count swaps and comparisons of elements. How can it be made more elegant and clear, if it is possible? I think using lots of tuples is not the best way to ...
0
votes
1answer
554 views

Efficiently Sorting File Paths [closed]

I'm trying to print out a list of files in a specific order, with files closer to the root directory sorted first. For example these files: c:\users\steve\foo.txt c:\users\bar.txt c:\users\steve\...
1
vote
2answers
73 views

Implementing multiple custom sorts [closed]

The following code works, but I'm sure there's a cleaner way to implement it and I'd appreciate any guidance on how to go about that. I have a class Result which I want to sort sometimes by score (...
3
votes
1answer
68 views

Multi-field sorting

A function to sort data on multiple fields. I welcome feedback. ...
2
votes
1answer
153 views

Sorting elements in array with a certain condition

This is what I have: function get_create returns a link with new filtered/sorted properties: Code on screenshot ...
1
vote
3answers
814 views

Efficient way to remove duplicate strings after adding their key values

How can I remove duplicate strings from a std::vector<std::pair<std::string,int>> after adding the int members of ...
1
vote
0answers
54 views

Sorting BIGINT column with ascending positive values followed by descending nonpositive values

I have a column flowing in with the full range of integers. Whilst generating keys on the INT column, I need to push the 0's and negatives down (ordered DESC) and ...
1
vote
1answer
935 views

pancake sorting using python

pancake sorting is implemented below. Algorithm is below: Find the largest out of order pancake and flip it to the bottom (you may need to flip it to the top of the stack first).Repeat step one until ...
0
votes
1answer
55 views

Traversing through single large array to convert single array into array of arrays as per condition

I have a huge fileList array where many elements of array start from sub-** pattern. I want to group these files belonging to ...
1
vote
1answer
356 views

Implemented heapsort algorithm in Java

I am learning algorithms by using Java. Here is an implementation of heapsort. Let me know if anything is wrong and and suggestion to improve the algorithm. ...
1
vote
1answer
1k views

Recursive quicksort in Python

I want to find a more elegant way to build a recursive sorting function. The function randomly selects one of the numbers from a given list, k, and splits the list ...
4
votes
1answer
160 views

Recursive Ruby merge sort

I have implemented a merge sort in Ruby. (Yes, I know, there's Array#sort) I would like to get feedback on code quality and optimization. ...
1
vote
2answers
128 views

Is there a better way to write insertion sort?

Background I am doing an insertion sort and I would like it to be as efficient as the algorithm allows. Code After much research, this is what I made: ...
2
votes
1answer
2k views

Making a faster parallel quicksort

I'm trying to take my existing parallel Quicksort and make it execute faster. Below is what I have but half the time the optimized version doesn't give me a faster time. I use them to compare big ...
2
votes
0answers
1k views

Visualization of sorting algorithms

I recently started to learn Qt framework and decided to create an app to visualize the sorting algorithms(for this moment there are 5 sorting algorithms). I just want to know if I'm doing everything ...
1
vote
1answer
151 views

Bubblesort using Writer monad

I still consider myself a newbie to functional programming, and I still have some trouble wrapping my head around a lot of functional concepts. Anyway, here goes: ...
1
vote
1answer
144 views

Making bubble sort pure and efficient

Background I am re-writing a series of algorithms together with a colleague that we are going to later on publish in a packet for the community. To start, I picked the typical bubble sort algorithm....
4
votes
0answers
543 views

Selection sort implementation in C++ iterator approach

I am trying to learn the C++ way of writing code. I was wondering if this code could be improved or if there are any major mistakes. Is it ok how I name the variables? ...
2
votes
1answer
170 views

Selection sort implementation in C++

I was wondering if this implementation of selection sort could be improved. Are there any things that I have done wrong? ...
1
vote
1answer
101 views

Bubble sort implementation in C++

I was wondering if this implementation of bubble sort could be improved. Are there any things that I have done wrong? ...
1
vote
1answer
418 views

C++ insertion sort implementation

I was wondering if this implementation of insertion sort could be improved. Are there any things that I have done wrong? ...
4
votes
2answers
565 views

Quicksort implementation in C++

I was wondering if this implementation of quicksort could be improved. Are there any things that I have done wrong? ...
1
vote
1answer
347 views

Merge sort implementation in C++

I was wondering if this implementation of merge sort could be improved. Are there any things that I have done wrong? ...
3
votes
2answers
6k views

Sort dictionary by increasing length of its values

Given a dictionary where the values are iterables, print the dictionary sorted by the length of its values. ...
2
votes
1answer
236 views

Radix sort implementation in JS (LSD)

I have written LSD radix sort implementation in JavaScript (6 functions in total). It sorts positive and negative integers: ...
5
votes
1answer
2k views

Ranking players in a league by sorting the contents of an OrderedDict

I'm new to python. I'm having second thoughts on my approach to this problem: The LeagueTable class tracks the score of each player in a league. After each game, the player records their score ...
-3
votes
1answer
66 views

MergeSort - Is this actually MergeSort?

Will this code actually work as MergeSort? This is working to sort the array but is it MergeSort? My faculty did approve of this but he probably did not see the code properly and I need some serious ...
44
votes
10answers
71k views

Given an array of integers, return the smallest positive integer not in it

Write a function: function solution(A); that, given an array A of N integers, returns ...
6
votes
4answers
1k views

Generic merge sort in C++ using a user-defined comparison function or the < operator by default

I wanted to implement a generic merge sort algorithm using the same interface as std::sort(). The interface takes first and last iterators to a range of elements in ...
5
votes
1answer
2k views

Iterative in-place quicksort

I have implemented an iterative in-place quicksort algorithm in Python, which by default selects the pivot as the last element: ...
1
vote
0answers
392 views

Last element pivot Quicksort exercise in TypeScript

Never being good in "algorithming", I'm now trying to improve the situation a bit. An algorithm below is the attempt to home brew yet another quicksort. This time, specifically with a "last-element" ...
1
vote
1answer
59 views

Java number sorting algorithm - remove ugly break

I have written a little number sorting algorithm that puts a random array of integers into ascending order, my code is below and it is working fine. However there is the very ugly and unsatisfying ...
4
votes
3answers
18k views

Sort numbers in ascending order using Python

This is Python code to sort the numbers in ascending order (It's my school task). How does it look? It works, but I think that this can be improved. ...
1
vote
1answer
1k views

Sorting linked list with comparator in Java

When I want to sort data on linked list by using collections.sort() and comparator will working after write (...
2
votes
1answer
117 views

Adaptive Mergesort in Java - follow-up

(See the previous and first iteration.) Adaptive Mergesort This algorithm is from a paper "Sublinear Merging and Natural Mergesort" by Svante Carlsson, Christos Levcopoulos and Ola Petersson. It ...
3
votes
1answer
318 views

Adaptive Mergesort in Java

(See the next iteration.) This natural merge sort here is from "Sublinear Merging and Natural Mergesort" by Svante Carlsson, Christos Levcopoulos and Ola Petersson. The funky part is that it may ...
6
votes
3answers
3k views

python (optimizing) bubble sort

I saw in Wikipedia (the first under Optimizing bubble sort) a pseudo-code to bubble sort and I implemented it in Python. I am posting my implementation here because I'm new to Python, and I'm looking ...
5
votes
1answer
109 views

Author class, with constructor validations and rich comparisons

I wrote the following Author class in Python for a project I'm working on. I wanted to make sure that the rich comparisons and the methods I used to validate the constructor parameters were done ...
3
votes
1answer
698 views

Measuring the time for the bubble sort algorithm

I created a program that measures the time for the bubble sort algorithm to sort a list of numbers: ...
1
vote
0answers
491 views

Sorting directed graph topological using Kahn's algorithm

For a course I'm doing I need to get up to speed with Java, but unfortunately only Java 1.6 - here is a topological sorting algorithm in said Java version, for practice reasons: ...
1
vote
2answers
2k views

Selection Sort in C++

I wanted feedback/review on my implementation of a selection sort in c++ (for ints only, no templates). This is my first attempt in c++ making anything beyond simple projects/hello world! Q: Should ...
3
votes
2answers
76 views

Sort a file on the first two columns, with optional filtering

I am a newbie to Rust and low-level coding. I come from data science and I have always used scripting languages so I may have done weird or useless things (with lifetimes and references). This is ...
2
votes
0answers
199 views

Comparing speed of common sorting algorithms in an extensible way

I have written a program with the goal of comparing the speed of some common sorting algorithms. It works with many data types. ...
5
votes
3answers
1k views

Sorting an array of objects by a property which may be missing

Problem I am sorting an array of objects. Each element may have a property called reference or it may be undefined. When ...
1
vote
2answers
503 views

Common Sorting Algorithms

Here I've prepared my solutions for the following algorithms, and was curious if there were a way to optimize any of them. Any input is welcome and appreciated! ...
6
votes
1answer
219 views

Finding added keys, removed keys, and unchanged keys in ordereddict

I'm comparing two OrderedDict objects and I need to find added keys, removed keys, and keys that are present in both (the intersection). Sets are designed for ...
6
votes
2answers
88 views

Ensuring Sequence of Events in an Array

The Problem I'm asking to see if there are methodically better solutions to this problem. The situation is as follows, I am receiving an array of events, they are marked by timestamp and there is a ...