Questions tagged [sorted]

This tag refers to a collection of items that has already been arranged in some specific order.

Use this tag for questions dealing with already sorted collections (i.e. reordering them, adding elements to them while still preserving the order, etc.).

297 questions
0
votes
1 answer

Using a binary search algorithm as a basis to implement a binary insert

I'm trying to implement a binary insert method. Currently this method is very simple, it takes an argument, in a while loop it searches for an element that is bigger than the argument (in this case a String that is the last name of a person), it…
Nobilis
  • 6,592
  • 1
  • 28
  • 58
0
votes
1 answer

Python sorted with list of alpha-numeric strings?

Here's the issue, I'm using the sorted function to arrange a list of alpha-numeric strings. The said strings have to numbers in them separated by a letter. For instance: sortqns(['s1q1', 's10q1', 's1q2', 's10q10', 's10q2']) def cmpqn(a, b): if…
tijko
  • 6,089
  • 11
  • 39
  • 54
-1
votes
3 answers

How to sort table?

I have IP table with 2 columns: IP and % what is the best way to sort this table according IP precent ? table type: public List statistics() { }
user979033
  • 2,656
  • 4
  • 23
  • 38
-1
votes
4 answers

Real time sorted by value, auto-discarding, bounded collection ?

I spent some time to try to make a collection that: 1) is sorted by value (not by key) 2) is sorted each time an element is added or modified 3) is fixed size and discard automatically smallest/biggest element depending of the sort way 4) is safe…
XmattZ
  • 1
-1
votes
1 answer

sorted array in java using swap methods

My problem is when I sort a list it will get the last element of the array wrong, ending up with it at the beginning of the array. In my example it fails to sort the last element which is 9, ending up printed first ahead of small numbers such as 0…
Zindu 5
  • 1
  • 1
  • 4
-1
votes
1 answer

Passing Argument in Python

I am new to python and trying to code an assignment but ran into some troubles. What I was trying to do so far are import a file into the program, return it to the main(). I created another function call print_names() to print the names in list…
Minh Le
  • 29
  • 4
-1
votes
2 answers

sorted() returning [] Python

f = open('2.txt', 'r') file_contents = f.read() print(file_contents) list = f.readline() print(sorted(f.readline())) is returning "[]" as it's output. The contents of the file is: Tom : 3 1 : 1 3 : 0 Tom : 1 You : 0 H :…
-1
votes
2 answers

Creating a sorted linked list in C

I am looking to create a method to insert a struct in ascending order by the PID's. I have been checking out other threads and I have written something out like others have mentioned but I get errors when compiling it regarding the Next_PCB and…
MrPorba
  • 59
  • 2
  • 6
-1
votes
1 answer

list is not callable error while using lambda

I'm currently working on a dataset for a clustering algorithm for which i need to sort the data points in accordance with the distances Here the data is of type ndarray(n-dimensional array) import numpy as np data =…
501shades
  • 1
  • 1
-1
votes
1 answer

Possible to "seed" a comparison function for use with sorted(...)

EDIT It would seem that my original question was flawed; I was confusing key with cmp as indicated by KillianDS and jonrsharpe. Using cpm with my class callable worked as expected. I've accepted jonrsharpe's answer as it's a more correct answer to…
Phillip B Oldham
  • 17,339
  • 17
  • 83
  • 127
-1
votes
1 answer

Sorting a dict in python

I have a dict as in below: saving = {0: (1, 2, 9.0), 1: (1, 3, 603.0), 2: (1, 4, 396.0), 3: (1, 5, 9.0), 4: (2, 3, 206.0)} I want to sort descending this dict order by the third value. I tried sorted and sort() but I couldn't sort the dict. I…
-1
votes
1 answer

What is most efficient method to store 3 max values found in a hashmap ? (java)

I have a hash map containing objects, I need to write a method which returns the 3 objects with a certain maximal value (calculated by another method), I am looking for the most efficient data structure to use. what I need is a data structure that…
Ethan
  • 221
  • 5
  • 15
-1
votes
2 answers

Why doesn't the Python sorted function take keyword order instead of reverse?

I'm trying to understand the logic behind why Python implemented sorted in what seems to be a less-than-self-documenting manner. If I want a list in descending order I do something like: [something[x] for x in sorted(something, reverse=True)] It…
bmacnaughton
  • 4,230
  • 2
  • 23
  • 32
-1
votes
3 answers

sorting distance in MySQL PHP

Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, boolean given in select My Code:
akhan
  • 73
  • 3
  • 10
-1
votes
1 answer

Do I need to create a new variable to store result of merge sorted list sequence?

I think I've done the right thing by not creating a new topic. Please correct me if I'm wrong. I've been given a question where I need to merge two sorted list-based sequences: S1 = (1,5,8,12) S2 = (7,9,11,18) 1. S1 = (5,8,12) S2 = (7,9,11,18) ? =…
1 2 3
19
20