Learn about singly linked list implementation in java, we have the largest and most updated singly linked list implementation in java information on alibabacloud.com
1 /*queues implemented with linked lists-using double-ended lists2 * NOTE: null pointer error must be reference not pointing to object3 * */4 Public classMylinkedqueue {5 Privatemyfirstandlastlinkedlist list;6 Private intitems;7 8 PublicMylinkedqueue () {9List =Newmyfirstandlastlinkedlist ();TenItems = 0; One } A - Public BooleanIsEmpty () { - returnList.isEmpty (); the } - - Public voidInsertintkey)
{Last.previous.next =null;last = last.previous;} } public void find (int value)//Find data{Node current = first;while (current.data! = value){Current =current.next;}Current.display ();} public void Finddelete (int value)//Find data and delete{Node current = first; if (First.data ==value){First =first.next;}Else{while (current.data! = value){Current =current.next;}Current.previous.next = Current.next;} } public boolean IsEmpty ()//Determine if the linked
left sub-leaf node of the current element.2. The next element of the doubly linked list constructed by the current node is the smallest node of the right child node of the current node, see 1.3. The previous element of the doubly linked list constructed by the current node is the node of the last operation.The code is as follows:public class Bstreenode {private Integer value;private bstreenode leftnode;pri
[] n =New int[100]; theArrays.fill (n,-1);113 intVal; the intCount = 0; the while(val = Sc.nextint ()) >= 0) { then[count++] =Val;117 }118 init (n);119 while(true){ - Printlist (head);121Print ("\nplease input the index and NUM to insert");122 intindex =sc.nextint ();123val =sc.nextint ();124 Insert (index, Val); the Printlist (head);126Print ("\nplease input the index to delete");127index =sc.nextint (); - Delete (index);129 Printlist (head)
last node to the header node instead of being NULL as a single-linked table. In this case, a new node is inserted after the last node.
2. When determining whether the end of the table is reached, it is to determine whether the value of the node chain domain is the header node. When the Chain Domain value is equal to the header pointer, it indicates that it has reached the end of the table. Instead of determining whether the Chain Domain value is NULL like a single-chain table.
In the development process, the encounter to generate a list object, you need to check every object inside it. However, this list sometimes has duplicate data. Therefore, it is necessary to go heavy to avoid duplicate checksums.
1. Writing without type:
List listwithoutdup = new ArrayList (new HashSet (Listwithdup));
2. With type (for example, Strin
This example for you to share the News list page query Java code for your reference, the specific content as follows
Package com.ibeifeng.test;
Create a news test class public class Newtest {private long id; private string title; private string content; private string author;
Public Newtest () {super ();}
Public newtest (long ID, string title, string content, string author) {this.id = ID;
Thi
On the previous blog, Web version RSS reader (i)--dom4j read XML (OPML) file has said how to read the RSS subscription file. This time read the subscribed files to the page and use the tree structure to load the display.
Do not intend to use a special control for the tree display, do not want to write their own, want to jingxiang some, just in
A JS tree script--dtree was found on the Internet. Dtree is an easy to use JavaScript tree
The Menu control. Supports infinite ratings, you can place m
/** Custom implementation of the javaslist collection structure */public class my‑list {private node firstnode; // always points to the first element private node lastnode; // always point to the last element private int size; // set length // Add public Boolean add (node) {If (null = node) {Throw new illegalargumentexception ("Node element with null not allowed");} If (null = firstnode) {firstnode = node;
This paper mainly introduces two methods of single-linked list inversion, which are recorded as follows:1.Package Com.leetcode;public class Listreverse {public static void main (string[] args) {node Node1 = new Node (1); Node Node2 = new node (2); Node Node3 = new node (3); Node Node4 = new node (4); node1.next = Node2;node2.next = Node3;node3.next = Node4; Node head = reverse (Node1); while (head! = null) {System.out.println (head.val); head = Head.n
From Java data structure and algorithm book
If the node is inserted, current points to the inserted element, and if the node is deleted, then current=current.next;
Here's the complete code:
Package com.xll; public class Interiterapp {public static void main (string[] args) {singlelinklist singlelinklist = new Singlelink
List ();
Iteratorlist iteratorlist = Singlelinklist.getiteratorlist ();
Iterato
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.