Linear meter is a linear structure, which is a limited sequence that has the same type N (n ≥ 0) data element.
1. Array
The array has upper and lower bounds, and the elements of the array are continuous in the upper and lower bounds.
The schematic diagram of the array of 10,20,30, 40, 50 50 is as follows:
Features of array : data is continuous; random access speed is fast.
The slightly more complicated array is multidimensional array and dynamic array. For the C language, the multidimensional array is also realized through one -dimensional array. As for the dynamic array, it is an array of the capacity of the index group that can dynamically grow; for the C language, if you want to provide a dynamic array, it needs to be manually implemented; for C ++, STL provides Vector; for Java, the Collection collection is concerned. Provides ArrayList and Vector.
Second, one -way linked list <br /> one -way linked list (single linked list) is a type of linked list. It consists of nodes. Each node contains the pointer of the next node.
The schematic diagram of a single linked list is as follows:
The head of the head is empty, the successor node of the head is "node 10" (node of data 10), and the successor node of "Node 10" is "Node 20" (data with data 10), ...
Single chain delete node
Delete "Node 30"
Before deleting: the successor node of "Node 20" is "Node 30", and the successor node of "Node 30" is "Node 40".
After deleting: the successor node of "Node 20" is "Node 40".
Single linked list added node
Add "Node 15" between "Node 10" and "Node 20"
Before adding: the successor node of "Node 10" is "Node 20".
After adding: the successor node of "Node 10" is "Node 15", and the successor node of "Node 15" is "Node 20".
The characteristic of a single linked list is that the link direction of the node is one -way; compared to the array, the random access speed of the single chain list is slow, but the single -linked list delete/add data is high.
Third, two -way linked list
The two -way linked list (dual linked list) is a type of linked list. Like a single linked list, the dual chain list is also composed of nodes. Each data node has two pointers, which point to direct successor and direct front -drive. Therefore, starting from any node in the two -way linked list, you can easily access its front -drive nodes and subsequent nodes. Generally, we all construct a two -way circular linked list.
The schematic diagram of the dual linked list is as follows:
The header is empty, the successor node of the head is "node 10" (node of data 10); the successor node of "node 10" is "node 20" (data 10 nodes), "node 20" pre -successor The node is "Node 10"; "Node 20" successor node is "Node 30", and the pre -node of "Node 30" is "Node 20"; ... the succession node of the end node is the head.
Double chain watch delete node
Delete "Node 30"
Before deleting: the successor node of "Node 20" is "Node 30", and the pre -node of "Node 30" is "Node 20". The successor node of "Node 30" is "Node 40", and the pre -node of "Node 40" is "Node 30".
After deleting: the successor node of "Node 20" is "Node 40", and the pre -node of "Node 40" is "Node 20".
Double link list adding nodes
Add "Node 15" between "Node 10" and "Node 20"
Before adding: the successor node of "Node 10" is "Node 20", and the previous node of "Node 20" is "Node 10".
After adding: the successor node of "Node 10" is "Node 15", and the pre -node of "Node 15" is "Node 10". The successor node of "Node 15" is "Node 20", and the previous node of "Node 20" is "Node 15".
The implementation of the dual chain list is introduced below, and the three implementations of C/C ++/Java are introduced respectively.
1. C implement a dual linked list
Implement the code two -way linked list file (double_link.h)
#Ifndef_double_link_h#DEFINE_DOUBLE_LINK_H // Create a "two -way linked list". Success, return to the head; otherwise, return the nulleXtern int Create_dlink (); // Rejected the "two -way linked list". Success, return 0; otherwise, return to -1extern int Destroy_dlink (); // "Whether the two-way linked list is empty". Return to 1 for emptiness; otherwise, return 0. extern int dlink_is_empty (); // Return to "the size of the two -way linked list" extern int dlink_size (); // Get the "element in the index position in the two -way linked list". Success, return to the node pointer; otherwise, return null. Extern void* dlink_get (int index); // Get the "first element in the two -way linked list". Success, return to the node pointer; otherwise, return null. extern void* dlink_get_first (); // Get the "last element in the two -way linked list". Success, return to the node pointer; otherwise, return null. extern void* dlink_get_last (); // insert "value" into the index position. Success, return 0; otherwise, return -1. extern int dlink_insert (int index, void *pval); // insert "value" into the head position. Success, return 0; otherwise, return -1. extern int dlink_insert_first (void *pval); // insert "value" into the end position. Success, return 0; otherwise, return -1. extern int dlink_append_last (void *pval); // Delete the "node in the index position in the two -way linked list". Success, return 0; otherwise, return to -1extern int dlink_delete (int int index); // Delete the first node. Success, return 0; otherwise, return to -1extern into dlink_delete_first (); // Delete a node after the group. Success, return 0; otherwise, return to -1extern int dlink_delete_last ();#Endif
Double_link.c in a two -way linked list
#include <STDIO.H> #include <Malloc.h>/*** C Lingle's two -way linked list can store arbitrary data. ** @AUTHOR SKYWANG*@Date 2013/11/07*/// Two -way linked list nodes typedef struct tag_node {stroct tag_node*prev; struct tag_node*next; void*p;} node ; // The head. Note that the value of the head does not store the element value! Intersection Intersection Static node *phead = null; // node number. Static int count = 0; // Create a new "node". Success, return to the node pointer; otherwise, return null. Static Node *Create_node (void *pval) {node *pNode = null; pNode = (node *) malloc (sizeof (node)); if (! PNODE) {Printf ("Create Node Error!/N. "); Return Null ;} // The default, the first node and the latter node of pNode point to its own pNode-> Prev = pNode-> Next = pNode; // The value of the node is pvalpnode-> p = pval; / Create a "two -way linked list". Success, return 0; otherwise, return -1. int Create_dlink () {// Create the header PHEAD = Create_node (NULL); if (! PHEAD) Return -1; // Set "node number" to 0Count = 0; Return 0;} // "Int dlink_is_empty () {Return Count == 0;} // Return to the" two -way linked list "int dlink_size () {Return Count;} // Get the" node in the INDEX position in the two -way linked list "static node* get_ node (node ( int index) {ifx <0 || Index> = Count) {Printf ("%S FAILED! Index Out of Bound!/N", __func __); Return null;} // is looking for if (index <= (Count/2)) {int i = 0; node *pNode = PHEAD-> Next; While ((i ++) <index) pNode = pNode-> Next; return pNode;} // reverse search int j = 0; int Rindex = Count -Index -1; Node * RNODE = PREV-> Prev; While ((J ++) <rindex) rnode = rnode-> Prev; Return RNODE;} // Get "first node" Static Node * g ET_FIRST_NODE () () Return get_node (0);} // Get the "last node" static node* get_last_node () {Return get_node (count-);} // Get the "element of index position in the two-way linked list". Success, return node value; otherwise, return -1. void * dlink_get (int index) {node * pindex = get_node (index); if (! Pindex) {printf ("%s failed!/n", __func __); > P;} //获取“双向链表中第1个元素的值”void* dlink_get_first(){return dlink_get(0);}// 获取“双向链表中最后1个元素的值”void* dlink_get_last(){return dlink_get(count- 1);} // insert "PVAL" into the INDEX position. Success, return 0; otherwise, return -1. int DLINK_INSERT (int index, void * pval) {// Insert the header IF (Index == 0) Return dlink_insert_first (pvalt (pval); // Get the node node corresponding to the position to be inserted. ; if (if (if !pindex)return -1;// 创建“节点”node *pnode=create_node(pval);if (!pnode)return -1;pnode->prev = pindex->prev;pnode->next = pindex;pindex- > Prev-> Next = pNode; pindex-> Prev = pNode; // Node number+1Count ++; Return 0;} // Insert "PVAL" into the head position of the head dlink_insert_firt (void *pval) {node *pNOD e = Create_node (pval); if (! pNode) Return -1; pNode-> Prev = PHEAD; pNode-> Next = PHEAD-> Next; PHEAD-> Prev = PNODE; NEXT = PNOD e; count ++; Return 0;} // Insert "PVAL" into the end position int dlink_append_last (void *pval) {node *pNode = create_node (pval); if (! pNode) Return -1; pNode-> Next = PHE AD; pNode-> Prev = PHEAD-> Prev; PHEAD-> Prev-> Next = PNODE; PHEAD-> Prev = PNODE; Count ++; Return 0;} // Delete the "node in the INDEX position in the two-way linked list". Success, return 0; otherwise, return -1. int DLINK_DELETE (int index) {node *pindex = get_node (index); if (! Pindex) {printf ("%s faced! The index in out of bound!/n", __func __); -1;} pindex- >next->prev = pindex->prev;pindex->prev->next = pindex->next;free(pindex);count--;return 0;}// 删除第一个节点int dlink_delete_first(){return dlink_delete (0);} // Delete a node int dlink_delete_last () {Return dlink_delete (count-);} // Revisit "two-way linked list". Success, return 0; otherwise, return -1. int Destroy_dlink () {if (! PHEAD) {Printf ("%s failed! Dlink is null!/n", __func __); Return -1;} node *pNode = PHEAD-> NEXT; node *ptmp = NUL L; While (pNode! = PHEAD) {ptmp = pNode; pNode = pNode-> Next; free (ptmp);} free (phead); phead = null; count = 0; Return 0;}
Two -way linked list test program (dlink_test.c)
#include <stdio.h> #include "double_link.h"/*** c language to implement a two -way linked list test program. ** (01) int_Test ()* Demonstrate "int data" in a two -way linked list. * (02) string_teest ()* Demonstrate "Strine Data" in a two -way linked list. * (03) Object_teest ()* Demonstrate the "object" in a two -way linked list. ** @AutHor Skywang* @date 2013/11/07* /// Two-way linked list operation int data void int_teest () {int iarr [4] = {10, 20, 30, 40}; Printf ("/n---- -%s ------ ", __func __); Create_dlink (); // Create a two-way linked list dlink_insert (0, & Iarr [0]); // Insert the data dlink_insert (0, & & & ig & & ig & & ig & & & & 1]); // Insert data dlink_insert (0, & ig igs [2]) to the header of the two -way linked list; // Plugs data printf ("dlink_is_empty () =%d/n", dlink_is_empty () ); // Whether the two -way linked list is empty printf ("dlink_size () =%d/n", dlink_size ()); // The size of the two -way linked list of the two -way linked list int i; int *p; int sz = dlink_size (); for (i = 0; i <sz; i ++) {p = (int *) dlink_get (i); propf ("dlink_get (%d) =%d/n", i, *p) } Destroy_dlink ();} void String_test () {char* sarr [4] = {"ten", "twenty", "thirty", "fringf ("/n ----%s ----%s- -/n ", __func __); create_dlink (); // Create a two-way linked list dlink_insert (0, sarr [0]); // Insert data dlink_insert (0, sarr [1]) to the header of the two-way linked list; // Insert data dlink_insert (0, sarr [2]) to the header of the two -way linked list; // Insert data printf ("dlink_is_empty () =%d/n", dlink_is_empty ()); // The two -way linked list Whether it is empty printf ("dlink_size () =%d/n", dlink_size ()); // The size of the two -way linked list // Print all the data int i in the two -way linked list; char *p; int sz = dlink_size (); For (i = 0; i <sz; i ++) {p = (char *) dlink_get (i); propf ("dlink_get (%d) =%s/n", i, p);} destroy_dlink ();} TypeDef Struct tag_stu {int ID; char name [20];} stu; static stu arr_stu [] = {10, "sky"}, {20, "jody"}, {30, "vic"}, {40, {40, {40, {40, {40, {40, "Dan"},};#define arr_stu_size ", __func __); create_dlink (); // Create a two -way linked list dlink_insert (0, & arr_stu [0]); // Insert data dlink_insert (0, & arr_stu [1]) to the two -way linked linked list to the two -way linked list. Data dlink_insert (0, & arr_stu [2]); // Insert data printf ("dlink_is_empty () =%d/n", dlink_is_empl ()); // Whether the two -way linked list is empty ("dlink_size () =%d/n", dlink_size ()); // The size of the two -way linked list // All data in the two -way linked list int i; int sz = dlink_size (); stu *p; for (i = 0; I <sz; i ++) {p = (stu *) dlink_get (i); proprintf ("dlink_get (%d) = [%d,%s]/n", i, p-> p-> name);} Destroy_dlink ();} int main () {int_test (); // Demonstrate "int data" in a two -way linked list. string_test (); // Demonstrate "string data" to a two -way linked list. object_test (); // Demonstrate "object" in a two -way linked list. Return 0;}
Running result
---- int_Test ---- dlink_is_empty () = 0dlink_size () = 3dlink_get (0) = 30d_get (1) = 20dlink_get 0dlink_size () = 3dlink_get (0) = Thirtydlink_get (1) = Twentydlink_get (2) = TEN ---- Object_test ---- DLINK_IS_EMPTY () = 0DLINK_SIZE () = 3dlink_get (0) = [30, vic] dlink_get (1) = [20 , Jody] dlink_get (2) = [10, Sky]
2. C ++ realizes dual chain list
Implement code two -way linked list file (doublelink.h)
#Ifndef Double_LINK_HXX#DEFINE DOUBLE_LINK_HXX#Include <iOSTREAM> USING NAMESPACE Std; Template <class T> Struct DNODE {PUBLIC: T Value; DNOD e *prev; dnode *next; public: dNode () {} dNODE (t, dNode * Prev, dNODE *Next) {this-> value = T; this-> Prev = Prev; this-> Next = NExt;}; Template <class t> class doublelink {public: doublelink (); ~ DoughLink (); int size (); int is_empty (); t get (int interns); t get_first (); t get_last (); int insert (int interm, t T); Cure ; int del (int index); int delete_first (); int delete_last (); private: int count; dNODE <t> *PHEAD; private: dNODE <T> *get_node (int index); }; Template <class T> Doughlink <t> :: dietylink (): Count (0) {// Create "Speed". Note: There is no storage data on the head! PHEAD = New DNODE <T> (); PHEAD-> Prev = PHEAD-> Next = PHEAD; // Set the linked list count to 0 // count = 0;} // The destructor template <class t> doublelink <t> :: ~ doughLink () {// Delete all nodes dNODE <t>* ptmp; dNODE <t>* pNode = PHEAD-> Next; While (pNode! = PHEAD) {ptmp = pNode; pNode = pNode-> Next ; delete ptmp;} // Delete the "head" delete phead; phead = null;} // Back the number of nodes template <class t> int DoubleLink <t>::) {Return Count;} // whether the return chain list为空template<class T>int DoubleLink<T>::is_empty(){return count==0;}// 获取第index位置的节点template<class T>DNode<T>* DoubleLink<T>::get_node (int index) {// Judgment parameter validity if (Index <0 || Index> = Count) {Cout << "Get Node Failed! The Index in Out of Bound!" << Endl; Return Null;} // Finding if (Index <= Count/2) {int i = 0; DNODE <T>* Pindex = PHEAD-> Next; While (i ++ <index) {pindex = pindex-> Next;} RETURN PINDEX;}/ / Reverse search int j = 0; int Rindex = Count -Index -1; DNODE <T>* PRINDEX = PHEAD-> Prev; While (j ++ <rindex) {propex = prINDEX-> Prev;} ReturnEx; }/ / The value of the node of the INDEX position TEMPLE <Class T> T DoubleLink <t> :: get (int index) {Return get_node (index)-> value;} // Get the value of the first node TEMPLE <Class T > Trivelink <t> :: get_first () {Return get_node (0)-> value;} // Get the value of the last node. UNT -1)-> Value;} // Insert nodes into the INDEX position before Template <class T> int Doublelink <T>:: Insert (int index, t T) {ifx == 0) Return Insert_first (T );; DNODE <T>* pNode = New DNODE <T, pindex-> Prev, PREV); pindex-> next = pNode; pindex-> prev = pNode; Count ++; Return 0;} // insert the node into the first node. Template <class t> int Doublelink <t> :: insert_fring (t) {dNode <t>* pNode = new dnode <t> (t, phead-> next); new-> next-> prev = pNode ; PHEAD-> Next = PNODE; Count ++; Return 0;} // Add the node to the end of the linked list. Dnode <t, PHEAD-> PREV, PHEAD); PHEAD-> Prev-> Next = PNODE; PHEAD-> Prev = PNODE; Count ++; Return 0;} // Delete index position TEMPLE <Class T> int Doublelink <t> :: DEL (int index) {dNode <t>* pindex = get_node (index); pindex-> next-> prev = pindex-> prev; pindex-> next = pindex-> next; delete pindex;count--;return 0;}// 删除第一个节点template<class T>int DoubleLink<T>::delete_first(){return del(0);}// 删除最后一个节点template<class T> int Doublelink <t> :: delete_last () {Return Del (Count-);}#Endif
Two -way linked list test file (dlinktest.cpp)
#include <iOSTREAM> #include "doublelink.h" using namespace std; // two -way linked list operation int data void inst_test () {4] = {10, 20, 40}; ---- int_Test ---- "<< Endl; // Create a two-way linked list DoubleLink <int>* pdlink = new doublelink <int> (); pdlink-> insert (0, 20); // insert 20 into The first position pdlink-> append_last (10); // add 10 to the end of the linked list at the end of pdlink-> insert_first (30); // Insert 30 to the first position // Whether the two-way linked list is empty << "is_empty () = "<< pdlink-> is_empty () << Endl; // The size of the two-way linked list is cout <<" "size () =" << pdlink-> size () << Endl; All data int sz = pdlink-> size (); for (int i = 0; i <sz; i ++) Cout << "pdlink (" << i << ") =" << pdlink-> get (i) << Endl;} void String_test () {String Sarr [4] = {"TEN", "Twenty", "Thirty", "Forty"}; Cout <</N ---- String_test ---- "" << ENDL; // Create a two-way linked list doublerink <string>* pdlink = new doublerink <string> (); pdlink-> insert (0, sarr [1]); // Insert the second element in Sarr into the first PDLink-> APPEND_LAST (SARR [0]); // Add the first element in Sarr to the end of the linked list at the end of the linked list pdlink-> insert_fring (sarr [2]); Position // Whether the two-way linked list is empty << "is_empty () =" << pdlink-> is_empty () << Endl; // The size of the two-way linked list cout << "size () =" << pdlink-> SIZE () << Endl; // All the data int sz = pdlink-> size (); for (int i = 0; i <sz; i ++) " <") =" << pdlink-> get (i) << Endl;} Struct Stu {int ID; char name [20];}; static stu arr_stu [] = {10, "sky"}, {20 20 , "Jody"}, {30, "vic"}, {40, "dan"},};#define arr_stu_size COUT << "/n ---- Object_test ----" << Endl; // Create a two-way linked list DoubleLink <STU>* pdlink = New DoubleLink <STU> (); PDLINK-> Insert (0, Arr_STU [1 [1 1 [1 ]; // Insert the second element in ARR_STU into the first position to PDLINK-> APPEND_LAST (ARR_STU [0]); // Add the first element in ARR_STU to the first element to the end of the linked pdlink-> insert_fring (ARR_STU [2 [2 2 [2 ]; // Insert the third element in ARR_STU to the first position // Whether the two-way linked list is empty << "is_empty () =" << pdlink-> is_empty () << ENDL; // The two-way linked list Cout << "size () =" << pdlink-> size () << Endl; // Print all the data int sz = pdlink-> size () in the two-way linked list; = 0; i <sz; i ++) {p = pdlink-> get (i); Cout << pdlink ("<< i <<") = [<< p.id << "," << p .name << "]" << Endl;} int main () {int_teest (); // Demonstrate "int data" to the two -way linked list. string_test (); // Demonstrate "string data" to a two -way linked list. object_test (); // Demonstrate "object" in a two -way linked list. Return 0;}
Example description
In the above example, I put the "statement" and "implementation" of the two -way linked list in the header file. The programming specifications warn us: separate the claim's declaration and implementation, and the amount of the header file (.h file or .hpp) contained only the statement, and was responsible for implementation in the implementation file (.cpp file)!
So why do you do this? This is because in the implementation of a two -way linked list, the template is adopted; and the C ++ compiler does not support the separate compilation of the template! To put it simply, if it is declared in DoubleLink.h and implemented in DoubleLink.cpp; when we create an object of DoubleLink in other categories, the error will be compiled. For specific reasons, you can refer to "why C ++ compilers cannot support separate compilation of templates".
Running result
---- int_Test ---- IS_EMPTY () = 0Size () = 3pdlink (0) = 30pdlink (1) = 20pdlink (2) = 10 ---- STRING_TEST -----EMPTY () = 0Size () = 3pdlink (0) = ThirdLink (1) = Twentypdlink (2) = TEN ---- Object_test ---- IS_EMPTY () = 0Size () = 3pdlink (0) = [30, VIC] pdlink (1) = [20 20 , Jody] pdlink (2) = [10, Sky]
3. Java realizes dual chain list
Doublelink.java implementation
/*** Java's two -way linked list. * Note: There is a two -way linked list in the collection package of Java. The path is: java.util.linkedlist ** @AutHor Skywang* @Date 2013/11/07*/Public Class DoubleLink <T> {// Top headpate DNODE <T> MHEAD; // Node number Private into mcount; // The structural class dnode <t> {public dNode next; public t; P Value; p Ublic DNode (T Value , DNODE Prev, DNODE NEXT) {this.Value = value; this.prev = prev; this.next = Next;} // Construct function public doublerink () {// Create "head". Note: There is no storage data on the head! MHEAD = New DNODE <T> (NULL, NULL, NULL); MHEAD.PREV = MHEAD.NEXT = MHEAD; // Initialize the "node number" to 0mcount = 0;} // return node number public into () {{ Return mcount;} // Whether the linked list is empty boolean isempty () {Return mcount == 0;} // The node Private DNODE <T> getNode (int index) {ifx) {INDEX <0 || Index> = mcount) Throw New Indexoutofboundsexception (); // Search for if (index <= mcount/2) {dNODE <t> node = mhead.next; INT I = 0; ; I ++) node = node.next;return node;}// 反向查找DNode<T> rnode = mHead.prev;int rindex = mCount - index -1;for (int j=0; j<rindex; j++)rnode = rnode. Prev; RNRN RNODE;} // Get the value of the node of the INDEX position. n getNode (0). Value;} // Get the value of the last node. t) {if (index == 0) {dNode <t> node = new dnode <t> (t, mhead, mhead.next); mhead.next.prev = node; mhead.next = node; ;; } DNODE <T> INODE = getNode (INDEX); DNODE <T> TNODE = New DNODE <T> (T, Inode.prev, Inode); inode.prev.next = TNODE; OUNT ++; Return ;} // Insert nodes into the first node. Public void Insertfirst (T T) {Insert (0, T);} // Add the node to the end of the linked list of the Public Void Appendlast (T T) {dNODE <t> NEW DNODE <T> (T, MHEAD.PREV MHEAD); mhead.prev.next = node; mhead.prev = node; mcount ++;} // The node Public Void Del (int index) {dNODE <T> inode = getNode (IN dex); inode.prev .next = inode.next; inode.next.prev = Inode.prev; INode = NULL; Mcount-;} // Delete the first node Public void deletefirst () {del (0);} // Delete the last last one Node Public void deletelast () {del (mcount-);}}
Test program (dlinktest.java)
/*** Java's two -way linked list. * Note: There is a two -way linked list in the collection package that comes with Java. The path is: java.util.linkedList ** @AutHor Skywang* @Date 2013/11/07*/Public Class DlinkTest {// Two -way linked table operation int data private static void int_teest () {int [] {10, 20, 30, 40}; System.out.println ("/n --- int_teest ----"); > dlink = New DoubleLink <Integer> (); dlink.insert (0, 20); // Insert 20 into the first position dlink.appendLast (10); // Add 10 to dlink.insertfirst (30 ) ;/ Insert 30 into the first position // Whether the two -way linked list is empty system.out.printf ("ISEMPTY () =%B/N", dlink.isempty ()); // .out.printf ("size () =%d/n", dlink.size ()); // Print all nodes for (int i = 0; i <dlink.size (); i ++) system.out .println ("dlink ("+i+") ="+dlink.get (i));} Private Static void String_test () {string [] sarr = {"ten", "twenty", "Thirty", "Forty" "}; System.out.println ("/n ---- string_test ---- "); // Create a two-way linked list DoubleLink <string> dlink = New DoubleLink <string> (); [1]); // Insert the second element in Sarr into the first position dlink.appendLast (sarr [0]); // Add the first element in Sarr to the end of the linked list dlink.insertfirs (SARR [2 2 2 2 ]; // Insert the third element in SARR to the first position // Whether the two -way linked list is empty system.out.printf ("isempty () =%b/n", dlink.isempty ());/ / System.out.printf ("size () =%d/ n", dlink.size ()); // Print all nodes for (int i = 0; i <dlink.size () ; I ++) System.out.println ("dlink ("+i+") ="+dlink.get (i));} // The internal class private static class student {Private String ID Student (int id, string name) {this.id = id; this.Name = name;}@ouverridePublic string tostring () {"+ID+", "+name+"] ";} tudent [] studers = New Student [] {New Student (10, "Sky"), New Student (20, "Jody"), New Student (30, "VIC"), New Student (40, "Dan"),}; object_test () {System.out.println ("/N ---- Object_test ----"); // Create a two-way linked list doublerink <student> dlink = new doublelink <student> (); students [1]); // Insert the second element in Students into the first position dlink.appendLast (studers [0]); // Add the first element in the students to dlink.insertfirst (Students [Students [Students [Students [ 2]); // Insert the third element in Students into the first position // Whether the two -way linked list is empty system.out.printf ("isempty () =%b/n", dlink.isempty ()); // System.out.printf ("size () =%d/n", dlink.size ()); // Print all nodes for (int i = 0; i <dlink.size () ); I ++) {system.out.println ("dlink ("+i+") ="+dlink.get (i));}} Public Static void Main (string [] arts) {int_Test (); // Demonstrate Operation "int data" in a two -way linked list. string_test (); // Demonstrate "string data" to a two -way linked list. object_test (); // Demonstrate "object" in a two -way linked list. }}
Running result
---- int_Test ---- ISEMPTY () = FalSeSize () = 3dlink (0) = 30dlink (1) = 20dlink (2) = 10 ---- STRING_TEST ——-- ISEMPTY () = FalSesize () = 3dlink (0) = Thirtydlink (1) = Twentydlink (2) = TEN ---- Object_teest --- Isempty () = falseSize () = 3dlink (0) = [30, vic] dlink (1) = [20 20 , Jody] dlink (2) = [10, Sky]
The above is all the contents of this article. I hope everyone can understand and help everyone.