算法排序的对象列表 [英] Algorithm for ordering a list of Objects

查看:127
本文介绍了算法排序的对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有对象的列表。用户主要使用的所有对象时,他正在工作。 你怎么可以订购的对象列表,因此该列表适应的顺序,用户大都采用?你可以用什么算法?

Say you have a List of objects. The User uses mostly all objects when he is working. How can you order the list of objects, so that the list adapts to the order, the users uses mostly? What algorithm can you use for that?

编辑:许多答案建议计算的时候一个对象被使用的次数。这不工作的,因为所有的对象中使用的相同量,只是以不同的顺序

Many answers suggested counting the number of times an object was used. This does not work, because all objects are used the same amount, just in different orders.

推荐答案

在你的对象,保持UsedCount上。只要对象时,增加此计数。 然后,你可以简单地做到这一点:

Inside your object, keep a usedCount. Whenever the object is used, increase this count. Then you can simply do this:

objects.OrderByDescending(o => o.UsedCount);

这篇关于算法排序的对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆