程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> c# 鏈表(LinkedList)使用

c# 鏈表(LinkedList)使用

編輯:C#入門知識

1public struct test
  2        {
  3            public string name;
  4            public string num;
  5        }
  6        public struct test1
  7        {
  8            public test st;
  9            public string name;
 10        }
 11        static void Main(string[] args)
 12        {
 13            LinkedList<test> t = new LinkedList<test>();
 14            test t1, t2;
 15            test1 tt1, tt2;
 16            t1.name = "t1";
 17            t1.num = "1";
 18            t2.name = "t2";
 19            t2.num = "2";
 20            t.AddFirst(t1);
 21            t.AddFirst(t2);
 22
 23            tt1.st = t1;
 24            tt2.st = t2;
 25            tt1.name = "tt1";
 26            tt2.name = "tt2";
 27            LinkedList<test1> tt = new LinkedList<test1>();
 28            tt.AddFirst(tt1);
 29            tt.AddFirst(tt2);
 30            LinkedListNode<test1> current11 = tt.FindLast(tt1);
 31            test1 tr1 = current11.Value;
 32
 33            LinkedListNode<test> current1 = t.FindLast(t1);
 34            test tr = current1.Value;
 35           
 36
 37            string[] words = { "the", "fox", "jumped", "over", "the", "dog" };
 38            LinkedList<string> sentence = new LinkedList<string>(words);
 39            Display(sentence);
 40
 41            Console.WriteLine("sentence.Contains("jumped") = {0}",
 42                sentence.Contains("jumped"));
 43
 44            // Add the word "today" to the beginning of the linked list.
 45            // Remove the new node, and add it to the end of the list.
 46            sentence.AddFirst("today");
 47            Display(sentence);
 48
 49            LinkedListNode<string> mark1 = sentence.First;
 50            sentence.RemoveFirst();
 51            sentence.AddLast(mark1);
 52            Display(sentence);
 53
 54            sentence.RemoveLast();
 55            sentence.AddLast("yesterday");
 56            Display(sentence);
 57
 58            mark1 = sentence.Last;
 59            sentence.RemoveLast();
 60            sentence.AddFirst(mark1);
 61            Display(sentence);
 62
 63            sentence.RemoveFirst();
 64
 65            LinkedListNode<string> current = sentence.FindLast("the");
 66            DisplayNode(current);
 67
 68            //sentence.Remove(current);
 69           
 70            sentence.AddAfter(current, "old");
 71            sentence.AddAfter(current, "lazy");
 72            DisplayNode(current);
 73
 74            current = sentence.Find("fox");
 75            DisplayNode(current);
 76
 77            sentence.AddBefore(current, "quick");
 78            sentence.AddBefore(current, "brown");
 79            DisplayNode(current);
 80
 81            // Keep a reference to the current node, "fox", and to the
 82            // previous node in the list. Use the Find method to locate
 83            // the node containing the value "dog". Show the position.
 84            mark1 = current;
 85     &nbs

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved