Questions tagged [sortedlist]

SortedList Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index. The capacity of a SortedList object is the number of elements the SortedList can hold. Use this tag for questions related to SortedList.

Filter by
Sorted by
Tagged with
0 votes
0 answers
32 views

Saving SortedList (C#) in MongoDB - Key Issue

The use of '.' in the key of a SortedList causes problems when saving in MongoDB because the '.' denotes the lower level. Ex: UpdateDefinition<User> updateDefinition = Builders<User>....
Philippe Lambert's user avatar
0 votes
1 answer
36 views

sortedcontainers.SortedKeyList: Return Element with Matching Value of Key

I am using sortedcontainers SortedKeyList to store a list of dictionaries. The dictionaries are sorted within the list by the value of a (nested) key (i.e., "token_str"). The SortedKeyList ...
user2514157's user avatar
0 votes
1 answer
37 views

Why I not am getting desired result while using == to compare elements of two SORTED arraylist [duplicate]

I want Make a new Arraylist of the common element from Two SORTED ARRAYLIST list1 and list2 I use "==" operator and got wrong answer the I used ".equals()" operator and got ...
Robot..'s user avatar
0 votes
1 answer
46 views

Arranging a sorted list in staggered order

I have a sorted list which I want to stagger the output of for another part of my project but can't figure it out the output should look like: Here is what I have so far (This was made with https://...
CJP's user avatar
  • 43
-1 votes
1 answer
36 views

I'm trying to find 1 in the array and getting -1. help me with the code in rotated sorted array

public class searchInRotatedSortedArray { public static void main(String[] args) { int[] arr = {3,4,5,6,7,0,1,2}; int target = 1; int peak = peak_ele(arr); ...
koyal kondapalli's user avatar
6 votes
1 answer
197 views

Why is foreach() on SortedList so memory expensive compared to Dictionary?

When optimizing a site, I tried to benchmark the code with Benchmark.Net. But I was surprised to find that some benchmarked code used 40,000 times more memory. After, too much, benchmarking I found ...
emilsteen's user avatar
  • 495
0 votes
2 answers
181 views

Python sortedcontainers is too slow

#This is my code from sortedcontainers import SortedList, SortedSet, SortedDict import timeit import random def test_speed1(data): SortedList(data) def test_speed2(data): sorted_data = ...
layssi's user avatar
  • 1
0 votes
1 answer
123 views

Is there any Alternative of Dictionary<Key, Value> with non contiguous memory allocation in C#

Using Dictionary<Key, Value> causing issues in memory allowing ( error Failed to allocate memory) in the application So is there any alternative which is allocate memory in non contiguous form. ...
Akash das's user avatar
  • 371
1 vote
2 answers
291 views

unsort a list to get it back the way it was

I want to unsort a list. For you to understand: list1 = ["Hi", "Whats up this Morning" "Hello", "Good Morning"] new_list = sorted(list1, key=len, reverse=True) ...
santni's user avatar
  • 21
-1 votes
1 answer
47 views

How to sort lines in file by number of words?

I've started a python course for beginners. I have a file with lines: "I was angry with my friend I told my wrath my wrath did end I was angry with my foe I told it not my wrath did grow" I ...
ddcrunk's user avatar
  • 23
-1 votes
1 answer
83 views

How can we have SortedList as a parameter in SortedDict in Python?

I am trying to use SortedList from sortedcontainers library as a parameter for SortedDict. Even though the Initialization maps = SortedDict(SortedList()) worked. I am Unable to insert any data into ...
Avinash Doddi's user avatar
-2 votes
3 answers
134 views

Sort all lists of values in dictionary [duplicate]

I have a dictionary, where keys are strings and values are all lists. For example: dict = {"Fruits": ["banana", "apple", "pear"], "Vegetables": ["...
beginner_in_python_1000's user avatar
0 votes
3 answers
583 views

How to sort a list of list with the first value, if the both are equal check the second and so on

If you are given a list of list (heterogenous). How do I sort it based on first value and if first value are equal then sort using the second value for those items and even if second values are equal ...
jdsouza's user avatar
-1 votes
2 answers
153 views

How do I temporarily sort a list alphabetically in reverse? [duplicate]

Like to use reverse sort in command its: variable.sort(reverse=True) but this is permanent. The sorted command is only temporary such as: print(sorted(variable)) so how do I make that one in reverse?
Captain Awesome's user avatar
-1 votes
2 answers
339 views

Find unique element in sorted array using c++

I am trying to find unique element from the array these is question Input : arr[] = {1, 2, 2, 3, 4, 4, 4, 5, 5} Output : arr[] = {1, 2, 3, 4, 5} They give me correct output but why they give 0 at ...
developer's user avatar
0 votes
0 answers
81 views

Iterator for Removing SortedLinkedList

I found a problem that my iterator cannot remove my data in sorted linked list although my data can be found to remove it. Can I ask for a solution ? My code package driver; import adt....
Alexander's user avatar
0 votes
2 answers
465 views

How to sort a list in descending order for the first criteria and ascending order for the second criteria?

I know that you can sort a list using multiple criterias with the sort or sorted functions, like this: list = sorted(list, key=lambda x:(x[0], x[1])) The code above sorts the list in ascending order ...
Jonas's user avatar
  • 416
0 votes
2 answers
481 views

How to filter a collection of objects by field value?

How in Python to organize and filter a collection of objects by a field value? I need to filter by being equal to an exact value and by being less than a value. And how to do it effectively? If I ...
Sengiley's user avatar
  • 233
0 votes
3 answers
208 views

What's the most efficient way to get an ordered list of values from SortedList<DateTime, float> where the keys satisfy a constraint?

By efficient I mean shortest time for computation. I came up with: List<float> valuesLaterThanDate = new List<float>(); foreach (var kvp in sortedList.Where( t => t.Key >= ...
Markus's user avatar
  • 1,068
0 votes
1 answer
105 views

Search a Sorted Array for First Occurrence of K

I'm trying to solve question 11.1 in Elements of Programming Interviews (EPI) in Java: Search a Sorted Array for First Occurrence of K. The problem description from the book: Write a method that ...
Andrew Schroeder's user avatar
0 votes
0 answers
51 views

Hide RecyclerView until List is sorted

When my RecyclerView loads it shows the unsorted list for a few milliseconds and then switches to the sorted list. Here is a video what it looks like: https://drive.google.com/file/d/...
Tyaaz's user avatar
  • 71
1 vote
4 answers
1k views

How to get the list of csv files in a directory sorted by creation date in Python

I need to get the list of ".csv" files in a directory, sorted by creation date. I use this function: from os import listdir from os.path import isfile, join, getctime def get_sort_files(...
nicc96's user avatar
  • 313
1 vote
3 answers
231 views

How to get the theoretic serial number of list elements if they were sorted by the sum in Python?

I have a list given filled with numpy arrays such as: lst = [np.array([1, 2, 3, 4, 5]), np.array([16, 17, 18, 19, 20]), np.array([6, 7, 8, 9, 10]), np.array([11, 12, 13, 14, 15])] ...
Máté Mázsi's user avatar
0 votes
1 answer
103 views

vba Add Item to SortedList causes an "Automation Error"

Why the following code causes an error: -2146233079(80131509). Sub testSortedList() Dim list Set list = CreateObject("System.Collections.SortedList") list.Add 1978340499, "a&...
lamplet's user avatar
  • 103
0 votes
1 answer
191 views

SortedList<Key, Value>: Error while changing the values inside a loop, while looping through the list / Unity, C#

I am having trouble programming this feature for a game i am making in Unity. I use a SortedList<GameObject, float> to store the interactable objects my player enter trigger with, and their ...
THK's user avatar
  • 38
0 votes
1 answer
227 views

How to insert a sorted node into a generic Linked list using java

I have encountered a problem while comparing the generic type data in which the compare to method isn't declared for comparing for example I used this to find the current and previous nodes in which ...
Lutfi's user avatar
  • 23
4 votes
2 answers
839 views

Split sorted list into two lists

I'm trying to split a sorted integer list into two lists. The first list would have all ints under n and the second all ints over n. Note that n does not have to be in the original list. I can easily ...
CarlosHSF's user avatar
0 votes
1 answer
371 views

Can I use System.Collections.Generic.SortedList in VBscript?

I'm trying to generate a sorted list in VBscript doing this: Set GNDcons = CreateObject( "System.Collections.Generic.SortedList<string, integer>" ) however it doesn't work, I get ...
Ariser's user avatar
  • 107
2 votes
0 answers
964 views

how does SortedList from sortedcontainers really work? Is it really a balanced BST?

for a balanced BST, it has an additional property of max difference of any two leaves' depth are no greater than 1, in additiona to BST property itself, thus achieving range query in O(logn) and is ...
hzhaoc's user avatar
  • 31
0 votes
0 answers
93 views

How to find the number of platform required by given arrival and departure information using python code

I have two list having trains timing of arrivals and departure as below: arrival = ["01:00", "01:07", "01:12", "01:14", "01:18", "01:25"] ...
Digital_AI's user avatar
0 votes
0 answers
219 views

SortedList which allows duplicate values

I need a list which enables sorted insertion while allowing duplicate sort values. SortedList as well as SortedSet from the System.Collections.Generic namespace for example do not allow duplicate ...
codymanix's user avatar
  • 28.7k
0 votes
2 answers
118 views

How do I access a structures component in the Sorted list. sortedList.GetByIndes(i).name?

Basically how do I access the component of a structure in my Sorted List (keys are strings and values are the structure). The structure is Section and one of the components of it is called name. How ...
Ethereallie's user avatar
2 votes
1 answer
250 views

SortedList does not find an element it contains while list does

In a project I am using a SortedContainers.SortedList. In the following pseudo-code, I am getting an assertion error: assert custom_class in list(sorted_list) # This does not cause an error assert ...
C Hecht's user avatar
  • 962
1 vote
2 answers
172 views

C# Grouping a sorted List by following value

I have a sorted "List orders". The list is already ordered and looks like this: class Order { public int Id { get; set; } public string Name { get; set; } public string DeliveryPerson { get; ...
Adrian's user avatar
  • 13
-1 votes
3 answers
39 views

How to get a list of dictionaries sorted by three criteria

I want to get a list sorted accordingly to the following rules persons.sort(key = lambda p: (abs(p["height"] - 180), p["weight"]==75, p["weight"])) i.e. I need it to get ...
lucasbbs's user avatar
  • 297
-1 votes
1 answer
59 views

Add to a list that is in a SortedList

I'm trying to add objects to a list that is inside a "sorted list" Example: public SortedList<string,List<ToolCommandDiscoveryHelper.DiscoveredTool>> categories { get; set; }
Timmie Nilsson's user avatar
0 votes
4 answers
354 views

Sorted Linked List on C Language

I have a problem here, I want to sort my Linked List with 3 data input, but when I executed this, only 1 data that be sorted. I have tried to mapping the temporary that will be replaced to a new nodes,...
MADFROST's user avatar
  • 1,163
0 votes
1 answer
300 views

How to track racing Game Car position using orderdBy List ? (Position based on Lap also)

In my Race Game, I am using a waypoint-based position tracking system. I am using an ordered list. Below is my code and it's working fine. IOrderedEnumerable<KeyValuePair<string, Player>> ...
Savad's user avatar
  • 1,252
-2 votes
1 answer
88 views

Sorted list of matrices ordered by their determinant in Python

I am trying to keep an ordered list of matrices where the ordering is given by the absolute value of the determinant. To do this I thought about using the SortedKeyList object in the sortedcontainers ...
mathma's user avatar
  • 99
1 vote
1 answer
62 views

How to convert SQLQuery to SortedList through EF6

I have an Entity Framework 6 class called Materials, which is reflected in my database as a table with the same name. Using a parent parameter, I need to return a sorted list of materials from a SQL ...
High Plains Grifter's user avatar
0 votes
1 answer
33 views

Why does the node not inserted at the end?

After I compile the code, there is no output at all. Why is the value 10 not inserted at the end of the linked list? I thought that after p == NULL, the while loop is exited, j->next would be NULL ...
John Lim's user avatar
1 vote
0 answers
86 views

Is there any List data structure that provides ordering while adding?

I need a list data structure that sorts as soon as an item is added. Like SortedSet does it, just allowing duplicates. Is there something like this in the .NET framework? I already checked the docs, ...
stefan.at.kotlin's user avatar
-2 votes
1 answer
161 views

const_iterator implementation in a sorted list class cpp

I'm trying to make a const_iterator but I have some trouble understanding it. I try to change stuff to make it work but it won't compile. Can somebody please help me understand what am I doing wrong? ...
SpaceNugget's user avatar
1 vote
1 answer
203 views

How to fix an error of trying to bind ':basic_string<char> >&' and ':basic_string<char> >' in cpp?

My code won't compile and I don't know how to fix it. It looks like the problem is maybe with the "=" operator but I'm not sure. I'm trying to apply a given function on the elements of the ...
SpaceNugget's user avatar
1 vote
2 answers
791 views

Adding in Sorted Linked List in C#

I have such a class for implementation of Sorted Linked List in C#. Now it's not actually sorted, but what changes do I have to make to this method it become one? class LinkedSortedList<T> { ...
BBB's user avatar
  • 13
2 votes
1 answer
718 views

How to take care of this error: invalid conversion from 'bool (*)(int)' to 'int'?

I'm writing this code for generic sorted list, and I have to write a filter method, without knowing what type of argument I will get. So I wrote it like that : #include <iostream> #include <...
SpaceNugget's user avatar
0 votes
0 answers
19 views

Process of executing calls from a recursion stack, how are the calls processed, what do they return and how does that matter?

I have heard that recursion calls take place from a stack. But the toughest thing, I find is how are they processed from the recursion stack? I have heard that the calls get stored sequentially inside ...
QUEEN's user avatar
  • 393
-2 votes
1 answer
180 views

I have been trying to merge 2 sorted linked lists using C++ but my output shows nothing ,just blank?

I have been trying to merge 2 sorted linked lists using C++ but my output shows nothing, just blank. In main function, I created 2 sorted linked lists and in the mergeem function I joined them by ...
Yash Kumar's user avatar
-2 votes
1 answer
325 views

How can I store an object by key in a sorted list?

I have two classes. One class is an object of the type public class Taksi { public int num; public string brand; public string FIO; public double mileage; // Here i missed get and ...
Cooler1337's user avatar
0 votes
1 answer
194 views

sorted array in php

in many languages like c#, java, etc, we have sorted array! it mean when we add some element to it, it will add new element in correct index base on sorting method ... with this algorithm inserting ...
Mahdi Youseftabar's user avatar

1
2 3 4 5
9