» Home » sorted » Page 1
Java Code Review: Merge sorted lists into a single sorted list
Category : Programming Languages

I want to merge sorted lists into a single list. How is this solution? I believe it runs in O(n) time. Any glaring flaws, inefficiencies, or stylistic issues?

I don't really like the idiom of setting a flag for "this is the first iteration" and using it to make sure "lowest" has a default value. Is there a better way around that?

public static <T extends Comparable

View Replies

how to create recursive merge of 2 sorted lists resulting in sorted merged list
Category : Programming Languages

I am learning about recursion I am trying to return a sorted list by merging 2 sorted lists and am getting lost Please help. I know this is incorrect already Any constructive help would be appreciated Thanks

public static ArrayList<Integer> mergeMyList(ArrayList<Integer> list1,
ArrayList<Integer> list2)

View Replies

Improving performance of merging lots of sorted maps into one sorted map - java
Category : Java

I have a method that gets a SortedMap as input, this map holds many SortedMap objects, the output of this method should be one SortedMap containing all elements of the maps held in the input map. the method looks like this:

private SortedMap mergeSamples(SortedMap map){
SortedMap mergedMap = new TreeMap();
Iterator sampleIt = map.values().iterator();

View Replies

Keeping a sorted list of elements, sorted by an attribute external to that element
Category : Programming Languages

I have a "manager" class maintaining a list of objects. Each Object has a certain "position", but this is not known to them, only the manager knows about this. The manager must assign each Object a position and maintain its list of Objects sorted according to this "external attribute".

Note that an Object's position can change at any time. Ideally I should be able to immediately get

View Replies

Python: Sorted representation of dict of lists, sorted by number of elements in list, after removing duplicates
Category : Coding

I have a dictionary that looks like this:

example_dict = {
0: [(1,2),(3,4),(3,4),(4,5)],
1: [(1,2),(3,4),(5,6),(7,8)],
2: [(4,5),(7,8)]}

I would like to get a sorted representation of this dictionary by number of elements in each list after 'temporarily' removing duplicates (only for the purpose of sorting, I don't want

View Replies

How to determine if one or more column in a large text file is sorted or not sorted
Category : Programming Languages

I have greater than 1GB big text file. The file has 4 columns delimited by TAB.

Col1: Guid
Col2: Date-time (yy-mm-yyyy 0000000000)
Col3: String
Col4: String

I want to determine if one or more of its column are sorted or not sorted.

Is there any quick way to do that? Maybe using Perl or some unix command? Or anything similar?

View Replies

efficient sorted Cartesian product of 2 sorted array of integers
Category : Development Tools & Services

Need Hints to design an efficient algorithm that takes the following input and spits out the following output.

Input: two sorted arrays of integers A and B, each of length n

Output: One sorted array that consists of Cartesian product of arrays A and B.

For Example:
A is 1, 3, 5
B is 4, 8, 10
here n is 3.
4, 8,

View Replies

Fast in-place partitioning of sorted array into two sorted subarrays
Category : Programming Languages

Edit - I removed all unnecessary context explanation - too wordy and ultimately irrelevant to the problem. In summary I'm partitioning arrays of coordinates during the process of building a balanced KD Tree (see wikipedia article, Construction section for more. I actually have k parallel arrays of n items that each have to be partitioned by the same comparison)

This is not homewor

View Replies

inserting element to a sorted vector and keeping elements sorted
Category : Programming Languages

So I have a vector, and I want the elements to be sorted at all times. How should I go about inserting an element into that vector and keeping the elements sorted when I pop them out. I looked into std::lower_bound, however, that gave the opposite of what I wanted.

For example, this is what I want: When I pop all the elements in the vector it should be:
1 2 3 4 5. That means t

View Replies

C++ How to merge sorted vectors into a sorted vector / pop the least element from all of them?
Category : Coding

I have a collection of about a hundred or so sorted vector<int>'s Although most vectors have a small number of integers in them, some of the vectors contain a large (>10K) of them (thus the vectors don't necessarily have the same size).

What I'd like to do essentially iterate through smallest to largest integer, that are contained in all these sorted vectors.

View Replies

2012 / 2017 Copyrights BigHow , All Rights Reserved .