标签: sorting

在字符串值中对数据排序

包含特定格式的日期和整数的字符串:MM/dd/yyyy(Number)

string strData = "01/23/2017 (5); 01/16/2017 (2);01/24/2017 (6);01/16/2017 (5);01/23/2017 (10)";
Run Code Online (Sandbox Code Playgroud)

基于以上我想要以下内容:

  1. 如果日期相似,请添加数字
  2. 排序应基于日期即升序

预期产出:

strData = "01/16/2017 (7);01/23/2017 (15);01/24/2017 (6)";    
Run Code Online (Sandbox Code Playgroud)

我知道有可能,如果我们在分号的基础上拆分,然后使用'for-loop'遍历值.

但请建议我linq解决方案.

c# linq sorting string date-format

1
推荐指数
1
解决办法
149
查看次数

如何在JavaScript中按时间对对象数组进行排序

我有一个对象数组,看起来像这样:

  • [0] = {运输号:“ 45”,时间:“ 10:28:00”,日期:“ 2017-01-16”}
  • [1] = {运输号:“ 45”,时间:“ 10:38:00”,日期:“ 2017-01-16”}
  • [2] = {运输号:“ 45”,时间:“ 10:48:00”,日期:“ 2017-01-16”}
  • [3] = {运输号:“ 14”,时间:“ 10:12:00”,日期:“ 2017-01-16”}
  • [4] = {运输号:“ 14”,时间:“ 10:24:00”,日期:“ 2017-01-16”}
  • [5] = {运输号:“ 14”,时间:“ 10:52:00”,日期:“ 2017-01-16”}

对象数组将始终看起来像是未排序的。首先按运输编号,然后按时间。这是由于我使用的api。

我的问题是:我如何只能按时间排序此数组?

我尝试在存储对象数组的变量上使用排序函数,如下所示,但没有成功:

allBuses.sort(function(a,b){
var c = a.time;
var d = b.time;

if(c > d){
return d
}

else return c
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting api time

1
推荐指数
2
解决办法
3443
查看次数

选择性地排序矢量c ++

我有以下向量:

vector<unsigned> vec = {5, 6, 5, 4, 1, 3, 0, 4}
Run Code Online (Sandbox Code Playgroud)

现在我想用奇数索引按字典顺序对这个向量进行排序(如果奇数索引相等,那么偶数索引).这样排序的矢量"vec"是:

   {0, 4, 1, 3, 5, 4, 5, 6}
Run Code Online (Sandbox Code Playgroud)

我知道std :: sort将完全排序"vec".是否可以使用std :: sort有选择地对向量进行排序.同样适用于std :: lower_bound.是否可以仅使用奇数索引找到lower_bound.

我想要与对矢量相同的效果.出于效率原因,我不将vec存储为对的向量.

c++ sorting vector c++11

1
推荐指数
1
解决办法
190
查看次数

获取表单的所有文本框,其名称按升序排列

我在一个表单中共有36个文本框,文本框的名称为txtBox1,txtBox2 ..... to txtBox36.其中一些textBox填写在form_load事件上.

我希望得到所有文本的盒子名称,它们是按升序排列的.

我尝试过的:

foreach (Control control in this.Controls)
{
    if (control is TextBox)
    {
        if (String.IsNullOrEmpty(control.Text))
        {
            for (int j = 1; j <= 36; j++)
            {
                MessageBox.Show(control.Name.ToString());
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

它给出的是随机顺序

txtBox26
txtBox28
txtBox31
txtBox34
txtBox33
txtBox30
txtBox27
txtBox29
txtBox25
txtBox14
txtBox16
txtBox19
txtBox21
txtBox18
txtBox17
txtBox23
txtBox24
txtBox13
txtBox7
txtBox10
txtBox6
txtBox3
txtBox11
txtBox12
Run Code Online (Sandbox Code Playgroud)

c# sorting visual-studio-2013

1
推荐指数
1
解决办法
832
查看次数

将javascript数组数组拆分为范围

我有一个数组,如:

[16, 20, 1, 4, 6, 8, 9, 22, 18, 14, 13, 12]
Run Code Online (Sandbox Code Playgroud)

我希望根据范围1-4,5-8,9-12,13-16,17-20,21-24分成6个不同的阵列.

使用javascript执行此操作的最简单方法是什么?

javascript arrays sorting split

1
推荐指数
1
解决办法
1804
查看次数

按字符串排序列表转换为int

我有一个保存为String的Int列表,我想订购它们。我想出了以下解决方案:

sortList = sortList.OrderByDescending(x => Convert.ToInt32(x.Number)).ToList();
Run Code Online (Sandbox Code Playgroud)

仅当列表仅包含数字时,它才能完美运行。例如,如果有一项是类似“ ???”的字符串 排序完全失败。

期望:

['313', '309', '119', '49', '???']
Run Code Online (Sandbox Code Playgroud)

结果:

['309' '49' '313' '119' '???']
Run Code Online (Sandbox Code Playgroud)

c# linq sorting list

1
推荐指数
1
解决办法
87
查看次数

Collections.sort在Java 1.7上不起作用

Java 6使用合并排序来比较Collections.sort()中的两个对象,而Java 1.7使用Timsort

我有这个课供对象排序

Class ObjectSort 
{
    String Name = "";
    int priority = 0;

    public ObjectSort (String name, int priority)
    {
        this.Name = Name;
        this.priority = priority;
    }

    public getPriority()
    {
        return priority;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的测试课是

TestClass 
{
     ...main()
    {
      List<ObjectSort> sorted = new ArrayList<ObjectSort> ();
      sorted.add ("Table", 99);
      sorted.add ("Chair", 1);
      Collections.sort(sorted, new Comparator ());
    }

 // inner class to define comparator logic
 private static final class Comparator implements  java.util.Comparator<ObjectSort>
 {
    @Override
    public int compare (ObjectSort f1, ObjectSort …
Run Code Online (Sandbox Code Playgroud)

java sorting collections comparator

1
推荐指数
1
解决办法
1194
查看次数

将所有零移动到列表的末尾(找不到0.0的解决方案)

假设我有一个列表:[9,0.0,0,9,1,2,0,1,0,1,0.0,3,0,1,9,0,0,0,0,9,False]我想将所有零移到最后.

这是我的代码:

def move_zeros(array):
    new = [int(x) if x is 0.0 else x for x in array ]
    new.sort(key=lambda item: item is 0)
    return new 
Run Code Online (Sandbox Code Playgroud)

但是int(x)不能为0.0没有第二行而工作我无法移动0.0到最后.能帮我找到解决方案0.0吗?

EDITED

我通过eding False到列表更新了原始帖子

python sorting type-conversion

1
推荐指数
1
解决办法
424
查看次数

Python:基于项和外键的排序列表

我有一个列表如下:

[['a', 123], ['b', 456], ['c', 789]]
Run Code Online (Sandbox Code Playgroud)

和字符串 cba

我想根据第一项和字符串cba所在的顺序对列表进行排序:

[['c', 789], ['b', 456], ['a', 123]]
Run Code Online (Sandbox Code Playgroud)

最好的方法是什么?

python sorting

1
推荐指数
1
解决办法
95
查看次数

在python 3中重复排序

我试图理解为什么zip在python 3中的对象上使用sorted函数不能多次执行.它只是第二次返回一个空列表.

In [34]: X = ["a", "b", "c", "d", "e", "f", "g", "h", "i"] 
    ...: Y = [ 0, 1, 1, 0, 1, 2, 2, 0, 1]
    ...: yx = zip(Y, X) 
    ...: yx 
    ...: [(0, 'a'), (1, 'b'), (1, 'c'), (0, 'd'), (1, 'e'), (2, 'f'), (2, 'g'), 
    ...: (0, 'h'), (1, 'i')] 
    ...: yx_sorted=sorted(yx)
    ...: 

In [35]: yx_sorted
Out[35]: 
[(0, 'a'),
 (0, 'd'),
 (0, 'h'),
 (1, 'b'),
 (1, 'c'),
 (1, 'e'),
 (1, 'i'),
 (2, 'f'), …
Run Code Online (Sandbox Code Playgroud)

python sorting python-3.x

1
推荐指数
1
解决办法
65
查看次数