算法笔试题: switch position of linked list's nth node and last nth node

April_dh 2015-03-17 03:08:15
一道英文算法题:
switch position of linked list's nth node and last nth node.
...全文
86 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
static void TestLinkedList()
        {
            LinkedList<int> list = new LinkedList<int>();
            foreach (var x in Enumerable.Range(5, 20))
            {
                list.AddFirst(x);
                Console.WriteLine(x);
            }
            var query = list.Select((n, i) => new { Value = n, Index = i });

            Console.WriteLine(query.Where(x => x.Index == 5).First().Value);
        }
Last nth的话就是颠倒过来算
bdmh 2015-03-17
  • 打赏
  • 举报
回复
第n个节点和最后一个节点换位置,找到第n个,要遍历,然后就是教会next或prio的指向即可,你可以先去了解一下链表

110,572

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧