I have a WinForms .NET datagrid whose data source is a List<cLineItem> called lines. cLineItem is very simple class with properties like units (int), description (string) and unit amount (float).
In code, i populate the list of lines and then set the data source:
dataGridView1.DataSource = lines;
This correctly populates the grid, ho...
As the title suggests i want to sort an array by value alphabetically in php.
$arr = array(
'k' => 'pig',
'e' => 'dog'
)
would become
$arr = array(
'e' => 'dog',
'k' => 'pig'
)
Any ideas?
EDIT: Here's the actual array i want to sort.
Array ( [0] => Newtown [1] => Montgomery [2] => Welshpool [6] => Llanfyllin [7] =...
How does one find the rank of each element of an array, averaging in the case of ties, efficiently? For example:
float[] rank(T)(T[] input) {
// Implementation
}
auto foo = rank([3,6,4,2,2]); // foo == [3, 5, 4, 1.5, 1.5]
The only way I can think of doing it requires allocating 3 arrays:
A duplicate of the input array because...
I have two very large lists and to loop through it once takes at least a second and I need to do it 200,000 times. What's the fastest way to remove duplicates in two lists to form one?
...
I'm working on a DAL method that uses an ORDER BY clause in a SELECT. The return value from the method is an IEnumerable<T>, where T is a class that encapsulates a domain entity, and the sort order would be based on one of the properties of this class, namely, "Priority." It's important that this ORDER BY works, of course, so I want to...
bool pred(int k, int l, int num1, int num2)
{
return (num1 < num2);
}
int main()
{
vector <int> nums;
for (int i=50; i > 0; --i)
{
nums.push_back(i);
}
std::sort (nums.begin(), nums.end(), boost::bind(&pred, 5, 45));
}
I am a boost newbie.
I was learning to use boost::bind and I wanted to sort a vector of intege...
This is really a double question, my two end goals having answers to:
What is the standard string comparison order, in terms of the mechanics?
What's a better name for that so I can update the docs?
Perl's documentation for sort says that without a block, sort uses "standard string comparison order". But what is that order? There sho...
Here is my code:
#include <stdio.h>
#include <string.h>
#include <errno.h>
int cmp(const void *a, const void *b) {
const char **ia = (const char **)a;
const char **ib = (const char **)b;
return strcmp(*ia, *ib);
}
void print_array(char **array, size_t len) {
size_t i;
for(i=0; i<len; i++) {
printf("%s, ", a...
Hi,
is there a data structure, which stores its elements uniquely (for a given compare-Functor) but answers queries for the highest element in that data structure with respect to another compare-Function ?
For Example: I have a class with two properties :
1) the size
2) the value
I'd like to have a data structure which stores all elem...
I've just read in a file that is something like:
name: john, jane
car: db9, m5
food: pizza, lasagne
Each of these rows (names, car, food) are in order of who owns what. Therefore John owns the car 'DB9' and his favourite food is 'Pizza'. Likewise with Jane, her car is an 'M5' and her favourite food is 'Lasagne'.
I effectively have:
...
If I have a size N array of objects, and I have an array of unique numbers in the range 1...N, is there any algorithm to rearrange the object array in-place in the order specified by the list of numbers, and yet do this in O(N) time?
Context: I am doing a quick-sort-ish algorithm on objects that are fairly large in size, so it would be ...
I've read this post and is hasn't ended up working for me.
Edit: the functionality I'm describing is just like the sorting function in Excel... if that makes it any clearer
Here's my situation, I have a tab-delimited text document. There are about 125,000 lines and 6 columns per line (columns are separated by a tab character). I've spl...
Suppose I have following data in my game. I have developed game in cocos2d.
Name Score
Sagar 10000
Amit 2000
Vishal 90
Above data is stored in plist file.
Plist has an array as root.
Within that there are 10 dictionary.
Each dictionary has two values.
String values - Name
Number value - score
When I use
NSMutableArray...
I often use the excellent find program in Bash to list files with certain filters. For example, in a Subversion (SVN) working copy, I sometimes wish to recursively list all files but excluding the .svn subdirectories as follows:
find . -name '.svn' -prune -o -type f -print
Today, I wanted to do something similar, but I also wanted to ...
I'm working on a game like Rodents Revenge, just to point out where I'm coming from with this question. I'm using the cocos2d game engine aswell...
I have a layer that contains about 168 blocks, these blocks are a subclass of a Sprite. Each block contains two instance variables that are integers, one for the xGridLocation and yGridLocat...
I'm looking for a way to sort my elements, but it isn't as easy as it sounds. Please let me explain
My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all thumbnails are inside one div
xx xx xx
xx xx xx
xx xx xx
The first column (6 x's) is visible and when you click on a button the ...
If possible, how can I improve the following quick sort(performance wise).Any suggestions?
void main()
{
quick(a,0,n-1);
}
void quick(int a[],int lower,int upper)
{
int loc;
if(lower<upper)
{
loc=partition(a,lower,upper);
quick(a,lower,loc-1);
quick(a,loc+1,upper)...
The following code rearranges elements by the attribute "amount". How can I alter this code so the items will be reversed? Thanks.
var parent = $('#items');
var children = $('a', parent);
children.sort(function(a, b) {
return parseInt($(a).attr('amount')) - parseInt($(b).attr('amount'));
})
$.each(children, function(i, child) {
...
How could I change the text below so that the text within it has a number appended to it.
<div class="right">This is some text</div>
<div class="right">This is some text</div>
<div class="right">This is some text</div>
So the code above would become,
This is some text
This is some text
This is some text
...
Well, I tested TreeMap but it doesn't take in account IgnoreCase on string comparision. I need to order lexicographically and ignoring case. Is there any other way?
Thanks, that works (TreeMap (Comparator c)). However, I have another question:
public final Comparator<Object> STR_IGN_CASE_COMP = new Comparator<Object>() {
public in...