RadComboBox Items Sorting with RadComboBoxSort.None - sorting

What happens to RadComboBox's Items after you call:
myCombo.Sort = RadComboBoxSort.None;
myCombo.Items.Sort();
???
Even when sort option is set to None, Items are sorted, but it is not sorted neither by Text nor Value. An items are ordered by random pattern which make no sense.

Use SortItems() method instead of Items.Sort().
Documentation says that these approaches are equal:
RadComboBox1.SortItems();
RadComboBox1.Items.Sort();
That is not exactly true. If Sort property is set to None, SortItems leaves items unsorted, but Items.Sort will do something unexpected.

Related

Why is sort function not sorting in Google Sheets

I have on row one cell A1 = 3, E1=9, I1=4.
If in cell K1 I write: =CONCATENATE(A1:I1) I get 394
But if I try to sort the cells before concatenating them with =CONCATENATE(SORT(A1:I1)) I still get the same result. Why?
This is due to the principle of the SORT function, which sorts rows according to data in columns. It does not sort individual cells. The example in the link explains more.
If you want to get the result that you anticipate, transpose your data and place them: A1=3, A5=9, A9=4
and perform: =CONCATENATE(SORT(A1:A9, 1, TRUE)), which gives you 349.
Or if you need to stick with row, transpose the cells in between. Use your original cell configuration and perform: =CONCATENATE(SORT(TRANSPOSE(A1:I1), 1, TRUE))
Note: Those additional parameters are required according to the SORT function help, however it seems that 1 and TRUE are used by default if they are missing.

Programming and data structures

Suggest a data structure for representing a subset S of integers from 1 to n. Following operations on the set S are to be performed in constant time (independent of cardinality of S).
You may assume that the data structure has been suitable initialized.
(i). MEMBER (X):
Check whether X is in the set S or not
(ii). FIND-ONE(S): If S is not empty, return one element of the set S (any arbitrary element will do)
(iii). ADD (X): Add integer X to set S
(iv). DELETE (X): Delete integer X from S.
My analysis:-
I think hash table will work fine here ,but how will hash table work for FIND-ONES(S) operation.Because i might need to scan the entire has table to look for the present element.
You can just use a regular hashset for this in java. In the case of the FIND-ONE(S) what you would do is, call isEmpty(). If that returns false, use the built in iterator, and just get the first value the iterator returns.
A hash table would work, but you need to think about the specific implementation. If you use the compact version from Python 3.6, you can perform FIND-ONEs in constant time by inspecting the entries list.
For example, the dictionary:
d = {'timmy': 'red', 'barry': 'green', 'guido': 'blue'}
is represented as follows:
indices = [None, 1, None, None, None, 0, None, 2]
entries = [[-9092791511155847987, 'timmy', 'red'],
[-8522787127447073495, 'barry', 'green'],
[-6480567542315338377, 'guido', 'blue']]

how to print a dictionary sorted by a value of a subdictionary?

I have a dictionary inside a dictionary and I wish to print the whole dictionary but sorted around a value in the sub dictionary
Lesson = {Name:{'Rating':Rating, 'Desc':Desc, 'TimeLeftTask':Timeleft}}
or
Lesson = {'Math':{'Rating':11, 'Desc':'Exercises 14 and 19 page 157', 'TimeLeftTask':7}, 'English':{'Rating':23, 'Desc':'Exercise 5 page 204', 'TimeLeftTask':2}}
I want to print this dict for example but sorted by 'Rating' (high numbers at the top)
I have read this post but i don't fully understand it.
If you could keep it simple it would be great.
And yes i'm making a program to sort and deal with my homework
Thanks in advance
def sort_by_subdict(dictionary, subdict_key):
return sorted(dictionary.items(), key=lambda k_v: k_v[1][subdict_key])
Lesson = {'Math':{'Rating':11, 'Desc':'Exercises 14 and 19 page 157', 'TimeLeftTask':7}, 'English':{'Rating':23, 'Desc':'Exercise 5 page 204', 'TimeLeftTask':2}}
print(sort_by_subdict(Lesson, 'Rating'))
As there is no notion of order in dictionary, we need to represent the dictionary as a list of key, value pair tuples to preserve the sorted order.
The so question you mention sorts the dictionary using the sorted function such that it returns a list of (k, v) tuples (here k means key & v means value) of top level dictionary, sorting by the desired value of sub dictionary v.

jqGrid permutation array

In jqGrid I am trying to use the permutation array for saving the reorder state of the columns.
For eg. Basic column state is perm = [0,1,2,3,4] column 3 is hidden and column 0 is the checkbox. Now I have a custom context menu which I use to finally give me a perm array of [0,1,3,2,4]
I have read in the documentation that the permutation array needs to start with 1, is this right?
When I try using "remapColumns" functions of the jqgrid and pass the perm array, it works fine. But if I try hiding and showing columns a couple of times, the column order is getting messed with.
Please help me understand what these indices for the permutation array stand for? Are they column indexes for visible columns? Should hidden columns be part of array? What happens in case of frozen columns? In some examples I have seen perm = [0:1, 1:3, 2:2, 3:1]
What is the correct way? I am using grid.jqGrid("remapColumns", perm, true);
Try to use also the last parameter of the function
grid.jqGrid("remapColumns", [0,1,3,2,4], true, false);
permutation, updateCells, keepHeader
wiki:methods

Data structure optimized for adding items (at end of list), iterating, and removing items

I need a data structure which will support the following operations in a performant manner:
Adding an item to the end of the list
Iterating through the list in the order the items were added to it (random access is not important)
Removing an item from the list
What type of data structure should I use? (I will post what I am currently thinking of as an answer below.)
You should use a linked list. Adding an item to the end of the list is O(1). Iterating is easy, and you can remove an item from any known position in the list in O(1) as well.
It sounds like a linked list, however there's a catch you need to consider. When you say "removing an item from the list", it depends on whether you have the "complete item" to remove, or just its value.
I will clarify: let's say your values are strings. You can construct a class/struct containing a string and two linking pointers (forwards and backwards). When given such a class, it's very easy to remove it from the list in O(1). In pseudo code, removing item c looks like this (please disregard validation tests):
c.backwards = c.forwards
if c.backwards = null: head = c.forwards
if c.forwards = null: tail = c.backwards
delete c
However, if you wish to delete the item containing the string "hello", that would take O(n) because you would need to iterate through the list.
If that's the case I would recommend using a combination of a linked list and and hash table for O(1) lookup. Inserting to the end of the list (pseudo code):
new_item = new Item(value = some_string, backwards = tail, forwards = null)
tail.forwards = new_item
tail = new_item
hash.add(key = some_string, value = new_item)
Scanning through the list is just scanning through the linked list, no problems:
i = head
while i != null:
... do something with i.value ...
i = i.forwards
Removing an item from the list by value (pseudo code, no validation testing):
item_to_remove = hash.find_by_key(some_string)
if (item_to_remove != null):
hash.delete_key(some_string)
item_to_remove.backwards = item_to_remove.forwards
if item_to_remove.forwards = null: tail = item_to_remove.backwards
if item_to_remove.backwards = null: head = item_to_remove.forwards
delete item_to_remove
I am thinking of using a simple list of the items. When a new item is added I will just add it to the end of the list. To remove an item, I won't actually remove it from the list, I will just mark it as deleted, and skip over it when iterating through the items.
I will keep track of the number of deleted items in the list, and when more than half of the items are deleted, I will create a new list without the deleted items.
Circular & Doubly-Linked List. It satisfies all 3 requirements:
Adding an item to the end of the list: O(1). By add to Head->prev. It supports Iterating through the list in the same order in which they were added. You can remove any element.
Assuming Java (other languages have similar structures, but I found the JavaDocs first):
ArrayList if you have the index of the item you want to delete
LinkedHashMap if you only have the item and not its position

Resources