首页 \ 问答 \ 排序少量元素(Sorting small numbers of elements)

排序少量元素(Sorting small numbers of elements)

我经常发现自己处于一种我想分类少数元素的情况。 小,我的意思是3或4.我认为这样的小问题集可能是正确的,我想要使用某种类型的显式或直接方法,而不是调用排序函数。 2是微不足道的,3个元素仍然非常简单,但超过4项左右,我开始更喜欢简单的运行插入排序。

至多有多少元素可以期待编码一个inline void sort_n(int *list)的好处? 4? 5? 6?

在这个主题中, 只用3个元素对int数组进行排序,有两种解决方案可以对提供的3个元素进行排序。 一个比较多,另一个比较最小,但比较复杂。 在现代化的建筑上,它会以最快的速度出现?


I am often finding myself in a situation where I want to sort a small number of elements. By small, I mean 3 or 4. I am probably correct in thinking that with such small problem sets I would want to use some type of explicit or direct method rather than invoking a sort function. 2 is trivial, 3 elements is still pretty simple but above 4 items or so and I'm starting to prefer the simplicity of just running insertion sort.

Up to how many elements can I expect a benefit to coding up a inline void sort_n(int *list)? 4? 5? 6?

In this topic, sorting int array with only 3 elements, there are two solutions for sorting 3 elements provided. One has more comparisons while the other minimizes comparisons but is more complicated. On a modern architecture, which would come out on top for speed?


原文:https://stackoverflow.com/questions/8627177
更新时间:2023-03-21 19:03

最满意答案

我只在Apple-apps上看过这个。 所以我猜他们有更广泛的API。 无论如何,你可以做一个解决方法。 初始化表时,可以使用

- scrollToRowAtIndex:

并指定第1行。现在这将是您数据的第一行。 索引0处的行将是一个带有按钮的行,该按钮将刷新表。 当您点击第0行时,您可以插入带动画的WKInterfaceImage(或者可能寻找自己做旋转轮的方法)。

这不是最佳方式,但如果你玩一下它可以使它工作并使它看起来很好。 希望这对你有所帮助。


I´ve only seen this on Apple-apps. So i guess they have a wider API. Anyway you can do a workaround. When you initialise your table you could use the

- scrollToRowAtIndex:

And specify row 1. This will now be your first row for your data. The row at index 0 will be a row with a button that will refresh the table. When you tap row 0 you could insert an WKInterfaceImage with an animation (or perhaps look for a way to do the spinning wheel yourself).

This is not the optimal way, but if you play around a little bit with it you can make it work and make it look good. Hope this helps you.

相关问答

更多
  • 您可以将scrollTop的值存储在一个cookie中,然后onload,将scrollTop设置回该值,但它可能会给用户带来生涩的体验。 您可能需要尝试为新数据创建XHR / Ajax调用,然后将其附加到页面上的正确位置。 你最喜欢的JS库会让你很容易做到。 You could store the value of scrollTop in a cookie, and then onload, set the scrollTop back to that value, but it will probab ...
  • 我终于实现了这一点,我在这里开源我的代码: https : //github.com/alexzielenski/ScrollToRefresh I finally achieved this and I open-sourced my code here: https://github.com/alexzielenski/ScrollToRefresh
  • 如何提供像/app/:currentScrollTop这样的路线,然后您可以根据该参数将视图滚动到所需位置。 How about providing a route like /app/:currentScrollTop and then you can based on that parameter to scroll your view to the desired position.
  • 请注意,这在Chrome中似乎不起作用。 何塞的回答似乎是目前最好的解决方案。 我把这个答案保留下来供参考。 基本上,如果使用锚点,我们绑定到Windows滚动事件。 这个想法是第一个滚动事件必须属于浏览器完成的自动重新定位。 当这种情况发生时,我们进行自己的重新定位,然后删除绑定的事件。 这样可以防止后续的页面滚动来破坏系统。 $(document).ready(function() { if (window.location.hash) { //bind to scroll f ...
  • 我只在Apple-apps上看过这个。 所以我猜他们有更广泛的API。 无论如何,你可以做一个解决方法。 初始化表时,可以使用 - scrollToRowAtIndex: 并指定第1行。现在这将是您数据的第一行。 索引0处的行将是一个带有按钮的行,该按钮将刷新表。 当您点击第0行时,您可以插入带动画的WKInterfaceImage(或者可能寻找自己做旋转轮的方法)。 这不是最佳方式,但如果你玩一下它可以使它工作并使它看起来很好。 希望这对你有所帮助。 I´ve only seen this on App ...
  • 我想知道你是如何在文档中监督这个简单的解决方案的? 这应该可以做到这一点: override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) { // Make changes to records... table.scrollToRowAtIndex(0) } 你的出路似乎也是错误的。 如果您使用IB创建它们,它会自动将它们标记为“弱”。 希望对你有帮助 :) I wonder how y ...
  • 这应该工作.... function doRefreshAndScroll(speed) { $('#load_tweets').load('http://myayg.com/index.php?route=salesTracker2.results', function(){ $('html, body').animate({ scrollTop: $(document).height() }, speed, function() { $(this).animate({ scrol ...
  • 这在MS PropertyGrid中是不可能的。 这个组件有太多无法访问的内部组件,为您提供了所要求的灵活性,并且您意识到自己不一致(您在网格下面有一个属性但在上面时没有这个问题)。 这就是我创建Smart PropertyGrid.Net的原因。 如果商业产品是您的选项,则此网格可以选择存储属性状态,并在对网格执行操作(如Refresh())后恢复它们,而不会出现任何闪烁。 This is not possible in the MS PropertyGrid. This component has to ...
  • 得到了答案: Private Sub Form2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move Me.ParentForm.PerformLayout() End Sub Got the answer: Private Sub Form2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move Me ...
  • 原来我可以使用ajax但我无法从我想要加载的页面中选择div。 我只能将页面中的整个html插入到我选择的div中。 但是有一个内存泄漏我无法弄清楚??? loc = window.location.pathname; //grabs page url pagediv1 = "#pageBody"; pathName = loc.substring(48, loc.lastIndexOf('.') + 4); //parses out url except for htm file name set ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)