在 C# 中旋转列表的最简单方法 [英] Easiest way to Rotate a List in c#

查看:39
本文介绍了在 C# 中旋转列表的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

列表说我有一个列表 List{1,2,3,4,5}

旋转意味着:

=> {2,3,4,5,1} => {3,4,5,1,2} => {4,5,1,2,3}

也许旋转不是最好的词,但希望你明白我的意思

Maybe rotate is not the best word for this, but hope you understand what I means

我的问题是,什么是最简单的方法(简而言之,c#4 Linq ready),并且不会受到性能的影响(合理的性能)

My question, whats the easiest way (in short code, c# 4 Linq ready), and will not be hit by performance (reasonable performance)

谢谢.

推荐答案

您可以将其实现为队列.Dequeue 和 Enqueue 相同的值.

You could implement it as a queue. Dequeue and Enqueue the same value.

**我不确定将列表转换为队列的性能,但人们对我的评论表示赞同,所以我将其发布为答案.

**I wasn't sure about performance in converting a List to a Queue, but people upvoted my comment, so I'm posting this as an answer.

这篇关于在 C# 中旋转列表的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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