Except list <t> the collection class does not have a similar version of a non-generic set. The linked list <t> is a two-way linked list. Its elements point to the elements before and after it.
The advantage of the linked list is that if you insert an element into the middle of the list, using the linked list will be very fast. When inserting an element, you only need to modify the next reference of the previous element and the previous reference of the next element so that they reference the inserted element. Insert an element in the list <t> and arraylist classes, and move all elements following the element.
Of course, linked lists also have disadvantages. The elements of the linked list can only be accessed one by one, which takes a long time to find the elements in the middle or end of the linked list.
A linked list not only stores elements in the list, but also stores the information of the next element and the previous element for each element. This is
The reason why the listnode <t> type elements exist. Use the javaslistnode <t> class to obtain the next element and the previous element in the list.
1 linked list test # region linked list test <br/> 2/*** // <summary> <br/> 3 // linked list test <br/> 4 /// </Summary> <br/> 5 public class testlinkedlist <br/> 6 {<br/> 7 public void testlinklist () <br/> 8 {<br/> 9 items list <book> booklist = new items list <book> (); <br/> 10 book book1 = new book {Title = "C # advanced programming", book_author = new author {name = "Huang laoxie", address = "Peach Blossom Island "}, price = 128f }; <br/> 11 book book2 = new book {Title = "thin K in Java ", book_author = new author {name =" Ouyang Feng ", address =" "}, price = 138f }; <br/> 12 book book3 = new book {Title = "Silverlight", book_author = new author {name = "", address = "Dali "}, price = 123f }; <br/> 13 book book4 = new book {Title = "javafx", book_author = new author {name = "", address = "Linan "}, price = 125f }; <br/> 14 book book5 = new book {Title = "WPF", book_auth OR = new author {name = "Wang Chongyang", address = "Linan"}, price = 158f }; <br/> 15 <br/> 16/** // Add book1 to the first element of the linked list <br/> 17 Booklist. addfirst (book1); <br/> 18/*** // Add book2 to the first element of the linked list, at this time, the first element will automatically return one digit <br/> 19 Booklist. addfirst (book2 ); <br/> 20 <br/> 21/** // instantiate a listnode object <br/> 22 bytes listnode <book> node = new bytes listnode <book> (book3); <br/> 23 <br/> 24/** // Add the listnode object to the end of the linked list. <br/> 25 book List. addlast (node); <br/> 26 <br/> 27/** // Add an element after the last element <br/> 28 Booklist. addafter (node, book4); <br/> 29 <br/> 30/*** // insert an element before the listnode object <br/> 31 Booklist. addbefore (node, book5); <br/> 32 <br/> 33 foreach (VAR item in booklist) <br/> 34 {<br/> 35 console. writeline (item. title ); <br/> 36} <br/> 37 <br/> 38 <br/> 39/** // display the order <br/> 40 // <br /> 41 console. writeline ("/n show elements in the linked list in sequence"); <br/> 42 Linke Dlistnode <book> firstnode = Booklist. First; <br/> 43 while (firstnode! = NULL) <br/> 44 {<br/> 45 console. writeline (firstnode. value. title); <br/> 46 firstnode = firstnode. next; <br/> 47 <br/> 48} <br/> 49 <br/> 50/** // display in reverse order <br/> 51 console. writeline ("/n reverse display elements in the Linked List"); <br/> 52 bytes listnode <book> lastnode = Booklist. last; <br/> 53 While (lastnode! = NULL) <br/> 54 {<br/> 55 console. writeline (lastnode. value. title); <br/> 56 lastnode = lastnode. previous; <br/> 57 }< br/> 58 <br/> 59 <br/> 60 console. writeline ("/n sorting result"); <br/> 61 <br/> 62 var orderlist = Booklist. orderby (Book => book. price); <br/> 63 <br/> 64 foreach (VAR item in orderlist) <br/> 65 {<br/> 66 console. writeline (string. format ("book name {0}, price {1}", item. title, item. price )); <br/> 67} <br/> 68 <br/> 69 <br/> 70} <br/> 71 <br/> 72} <br/> 73 <br /> 74 # endregion