GVKun编程网logo

coding++:对List中每个对象元素按时间顺序排序(list 对象排序)

13

在本文中,我们将给您介绍关于coding++:对List中每个对象元素按时间顺序排序的详细内容,并且为您解答list对象排序的相关问题,此外,我们还将为您提供关于"随笔"列表-按时间先后顺序排列、an

在本文中,我们将给您介绍关于coding++:对List中每个对象元素按时间顺序排序的详细内容,并且为您解答list 对象排序的相关问题,此外,我们还将为您提供关于"随笔" 列表 - 按时间先后顺序排列、angularjs – ng-repeat:对象数组中每个对象的访问键和值、c# – 如何将IEnumerable转换为List,其中每个对象都是IFoo?、C++程序:将数组元素按降序排序的知识。

本文目录一览:

coding++:对List中每个对象元素按时间顺序排序(list 对象排序)

coding++:对List中每个对象元素按时间顺序排序(list 对象排序)

需求: 需要对List中的每个User按照birthday顺序排序,时间由小到大排列。

package com.tree.ztree_demo.orderby; import java.text.SimpleDateFormat; import java.util.*; public class ListSort { public static class UserBean { private String id; private String birthday; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) { this.birthday = birthday; } } public static void main(String[] args) { List<UserBean> list = new ArrayList<UserBean>(); UserListGenerate(list); System.out.println("********排序前*******"); for (UserBean user : list) { System.out.println(user.getBirthday()); } ListSort(list); System.out.println("******排序后*****"); for (UserBean user : list) { System.out.println(user.getBirthday()); } } private static void UserListGenerate(List<UserBean> list) { UserBean user1 = new UserBean(); UserBean user2 = new UserBean(); UserBean user3 = new UserBean(); user1.setId("zhagnsan"); user1.setBirthday("1980/11/01"); user2.setId("lisi"); user2.setBirthday("1981/12/01"); user3.setId("wangwu"); user3.setBirthday("1980/12/01"); list.add(user1); list.add(user2); list.add(user3); } private static void ListSort(List<UserBean> list) { Collections.sort(list,new Comparator<UserBean>() { @Override public int compare(UserBean o1,UserBean o2) { SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); try { Date dt1 = format.parse(o1.getBirthday()); Date dt2 = format.parse(o2.getBirthday()); if (dt1.getTime() < dt2.getTime()) { return 1; } else if (dt1.getTime() > dt2.getTime()) { return -1; } else { return 0; } } catch (Exception e) { e.printstacktrace(); } return 0; } }); } }

"随笔" 列表 - 按时间先后顺序排列

  1. 这是一个测试
  2. linux 采用 scp 命令拷贝文件到本地,拷贝本地文件到远程服务器
  3. 美化博客园
  4. virtual box 虚拟机在 linux 下设置共享文件夹
  5. 纯净版 linux (debian)挂载 VirtualBox 共享文件夹
  6. virtualbox 挂载目录失败 mount: unknown filesystem type ‘vboxsf’
  7. linux 系统相关命令
  8. linux 调试相关命令
  9. 虚拟机 virtualbox,直接复制本机虚拟硬盘 vdi 使用,会提示错误的解决方法
  10. 小小输入法挂载小鹤双拼
  11. 博客园增加打赏功能
  12. 史上最全颜色在古代的叫法 (快速搜索)
  13. mac 同时享受教育优惠和免手续费分期
  14. 管理 windows 自启动程序
  15. HTTP 文件共享服务器工具 - chfs
  16. 在 WIN7、WIN10 操作系统用 WebDAV 映射网络驱动器需要的操作
  17. c++ 子类构造函数初始化及父类构造初始化
  18. 编程变量名
  19. markdown 图片设置
  20. [转载] Linux 新手必看:浅谈如何学习 linux
  21. Linux 下的 tar 压缩解压缩命令详解

angularjs – ng-repeat:对象数组中每个对象的访问键和值

angularjs – ng-repeat:对象数组中每个对象的访问键和值

我有一个对象数组,我使用ng-repeat迭代它们,这很容易。数组看起来像这样:
$scope.steps = [
    {companyName: true},{businessType: true},{physicalAddress: true}
];

我的ng-repeat属性看起来像:

<div ng-repeat="step in steps"> ... </div>

在每次迭代中,步骤等于对象之一,如预期的那样。有没有访问的两个键和step对象的值?所以我可以做这样的事情:

<div ng-repeat="(stepName,isComplete) in steps"> ... </div>

其中stepName ==’companyName’和isComplete == true。我试过做这个确切的事情,但stepName总是只是最终作为步骤对象的索引(这是有道理的)。我只是想弄清楚是否有另一种方式来编写ng-repeat语法,以便我可以获得键和值。

感谢任何想法/建议。非常感激。

PS。我目前的工作是在我的控制器:

$scope.stepNames = [];
angular.forEach($scope.steps,function(isComplete,stepName){
     $scope.stepNames.push({stepName: stepName,isComplete: isComplete});
});

然后迭代这个,但它是很好的做所有在视图中

中继器内的中继器
<div ng-repeat="step in steps">
    <div ng-repeat="(key,value) in step">
        {{key}} : {{value}}
    </div>
</div>

c# – 如何将IEnumerable转换为List,其中每个对象都是IFoo?

c# – 如何将IEnumerable转换为List,其中每个对象都是IFoo?

如何转换IEnumerable< object>列出< IFoo>每个对象都是IFoo?

我有一个IEnumerable< object>,someCollection,someCollection中的每个项目都是一个IFoo实例.如何将someCollection转换为List< IFoo>?我可以使用转换或强制转换或其他东西而不是循环并构建列表吗?

解决方法

使用LINQ,您可以使用 Cast来转换项目,并使用 ToList获取列表.

尝试:

IEnumerable<object> someCollection; //Some enumerable of object.
 var list = someCollection.Cast<IFoo>().ToList();

C++程序:将数组元素按降序排序

C++程序:将数组元素按降序排序

c++程序:将数组元素按降序排序

在解决一些问题时,以适当的形式排列数据项是一项重要的任务。

efficient way. The element sorting problem is one of the most commonly discussed 排列问题。在本文中,我们将看到如何排列数组元素 按照它们的值降序排列(在C++中)。

在这个领域中有许多不同的排序算法用于对数字或非数字进行排序

按给定顺序的元素。在本文中,我们将只介绍两种简单的方法 sorting. The bubble sort and the selection sort. Let us see them one by one with proper 算法和C++实现代码。

使用冒泡排序技术按降序对数组进行排序

冒泡排序技术是一种最常见且较简单的排序方法。

数组中的元素。此方法检查两个相邻的元素,如果它们是正确的 order, then skip to the next elements, otherwise interchange them to place them in correct 将其它元素顺序排列,然后跳过到下一个元素,否则交换它们以将其放置在正确位置 order. Then move towards right and do the same for the other pair of values. The bubble 按顺序排列。然后向右移动,并对另一对值执行相同操作。气泡 排序技术有几个阶段,在每个阶段结束时,一个元素被放置在 正确的预期位置。让我们来看一下冒泡排序技术的算法。

算法

  • 读取数组A及其大小n作为输入
  • 对于i从0到n-1的范围,执行
    • 对于 j 从 0 到 n - 2 的范围,执行
      • 如果 A[j]
      • 交换 A[j] 和 A[j + 1]
  • 结束如果
  • end for
  • end for
  • Example

    #include <iostream>
    using namespace std;
    void display( int arr[], int n ){
       for ( int i = 0; i < n; i++ ) {
          cout << arr[i] << ", ";
       }
    }
    void swap ( int &a, int &b ){
       int temp = a;
       a = b;
       b = temp;
    }
    void solve( int arr[], int n ){
       int i, j;
       for ( i = 0; i < n; i++ ) {
          for ( j = 0; j < n-1; j++ ) {
             if ( arr[j] < arr[ j+1 ] ) {
                swap( arr[j], arr[ j + 1 ] );
             }
          }
       }
    }
    int main(){
       int arr[] = {8, 45, 74, 12, 10, 36, 58, 96, 5, 2, 78, 44, 25, 12, 89, 95, 63, 84};
       int n = sizeof( arr ) / sizeof( arr[0] );
       cout << "Array before sorting: ";
       display(arr, n);
       solve( arr, n );
       cout << "\nArray After sorting: ";
       display(arr, n);
    }
    
    登录后复制

    输出

    Array before sorting: 8, 45, 74, 12, 10, 36, 58, 96, 5, 2, 78, 44, 25, 12, 89, 95, 63, 84, 
    Array After sorting: 96, 95, 89, 84, 78, 74, 63, 58, 45, 44, 36, 25, 12, 12, 10, 8, 5, 2, 
    
    登录后复制

    使用选择排序技术将数组按降序排序

    在选择排序技术中,我们找到最小元素或最大元素 从给定数组中的索引i开始,翻译为中文:element from the given array starting from index i to the end of this array. Assume we are. 找到最大元素。在每个阶段中,它从索引i到末尾找到最小值,然后 将元素放置在其所需的位置,然后再次搜索下一个最大元素 the index i + 1 and so on. After completing these phases, the entire array will be sorted 索引 i + 1 等等。完成这些阶段后,整个数组将被排序 相应地。

    算法

    • 读取数组A及其大小n作为输入
    • 对于i从0到n-1的范围,执行
      • ind := 从 i 到 n 中 A 的最大元素的索引
      • 如果 A[ i ] < A[ ind ],那么
        • 交换 A[ i ] 和 A[ ind ]
      • 结束如果
    • end for

    Example

    #include <iostream>
    using namespace std;
    void display( int arr[], int n ){
       for ( int i = 0; i < n; i++ ) {
          cout << arr[i] << ", ";
       }
    }
    void swap ( int &a, int &b ){
       int temp = a;
       a = b;
       b = temp;
    }
    int max_index( int arr[], int n, int s, int e ){
       int max = 0, max_ind = 0;
       for ( int i = s; i < e; i++ ) {
          if ( arr[i] > max ) {
             max = arr[i];
             max_ind = i;
          }
       }
       return max_ind;
    }
    void solve( int arr[], int n ){
       int i, j, ind;
       for ( i = 0; i < n; i++ ) {
          ind = max_index( arr, n, i, n );
          if ( arr[i] < arr[ ind ] ) {
             swap( arr[i], arr[ ind ] );
          }
       }
    }
    int main(){
       int arr[] = {8, 45, 74, 12, 10, 36, 58, 96, 5, 2, 78, 44, 25, 12,89, 95, 63, 84};
       int n = sizeof( arr ) / sizeof( arr[0] );
       cout << "Array before sorting: ";
       display(arr, n);
       solve( arr, n );
       cout << "\nArray After sorting: ";
       display(arr, n);
    }
    
    登录后复制

    输出

    Array before sorting: 8, 45, 74, 12, 10, 36, 58, 96, 5, 2, 78, 44, 25, 12, 89, 95, 63, 84, 
    Array After sorting: 96, 95, 89, 84, 78, 74, 63, 58, 45, 44, 36, 25, 12, 12, 10, 8, 5, 2,
    
    登录后复制

    结论

    排序问题是一个基本问题,我们在其中排列数字或其他值

    立即学习“C++免费学习笔记(深入)”;

    在给定的排列逻辑中。在这里有许多不同的排序技术可用 理解和实现 实现和易于理解。这两种方法是冒泡排序技术和 选择排序技术。使用这两种方法,我们已经对数据集进行了排序 降序(非递增)排序。这两种排序方法在效率上并不高 尊重时间,但它们很容易理解。这两种方法都需要O(n2)的时间 时间量,其中n是输入的大小。通过简单的方式,冒泡排序可以变得更快 检查是否在任何阶段都没有交换时,下一个连续阶段不会发生 改变任何事物。

    以上就是C++程序:将数组元素按降序排序的详细内容,更多请关注php中文网其它相关文章!

    今天关于coding++:对List中每个对象元素按时间顺序排序list 对象排序的介绍到此结束,谢谢您的阅读,有关"随笔" 列表 - 按时间先后顺序排列、angularjs – ng-repeat:对象数组中每个对象的访问键和值、c# – 如何将IEnumerable转换为List,其中每个对象都是IFoo?、C++程序:将数组元素按降序排序等更多相关知识的信息可以在本站进行查询。

    本文标签: