当前位置 :
givemeananswerclassProgram{staticvoidMain(string[]args){LinkedListlist=newLinkedList();list.AddFirst(10);list.AddLast(20);list.AddLast(30);list.AddLast(40);Theaboveprogramisincomplete,pleasecompletetheaboveprogramtoperformfollo
1人问答
问题描述:

givemeananswer

classProgram

{

staticvoidMain(string[]args)

{

LinkedListlist=newLinkedList();

list.AddFirst(10);

list.AddLast(20);

list.AddLast(30);

list.AddLast(40);

Theaboveprogramisincomplete,pleasecompletetheaboveprogramtoperformfollowingoperationsonlinkedlist,theoperationstobeperformedare:

i.Displaytotalnumberofnodesintothelinkedlist

ii.Addvalue:25after20.

iii.Addvalue5before10

iv.Checkthatthelistcontainsvalue30,ifcontainsdisplayamessage“30isintothelinkedlist”

v.Displaythevaluesofallthenodesfromthelinkedlist.

胡海星回答:
  using System;   using System.Collections.Generic;   using System.Text;   namespace LinkedListDemo   {   class Program   {   static void Main(string[] args)   {   LinkedList<int> list = new LinkedList<int>();   list.AddFirst(10);   list.AddLast(20);   list.AddLast(30);   list.AddLast(40);   //i. Display total number of nodes into the linked list   Console.WriteLine("Total number of nodes:{0}", list.Count);   //ii. Add value : 25 after 20.   list.AddAfter(list.Find(20), 25);   //iii. Add value 5 before 10   list.AddBefore(list.Find(10), 5);   //iv. Check that the list contains value 30, if contains display a message “30 is into the linked list”   if (list.Contains(30)) {   Console.WriteLine("30 is into the linked list");   }   //v. Display the values of all the nodes from the linked list.   foreach (int value in list) {   Console.Write("{0} ", value);   }   Console.ReadKey();   }   }   }
最新更新
PC端 | 移动端 | mip端
字典翻译(zidianfy.com)汇总了汉语字典,新华字典,成语字典,组词,词语,在线查字典,中文字典,英汉字典,在线字典,康熙字典等等,是学生查询学习资料的好帮手,是老师教学的好助手。
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
电话:  邮箱:
Copyright©2009-2021 字典翻译 zidianfy.com 版权所有 闽ICP备2022014709号-7
lyric 頭條新聞