Due to the holiday, I have left 10 fields without algorithms. I just returned to school today and started my algorithm journey again.
Today, we mainly use java to describe the implementation process of linked lists.
Worker Node
1 publicclassjavasnode {
2 protectedObject item;
3 protected1_node nextNode;
4 public1_node (Object x)
5 {
6 item = x;
7 nextNode = null;
8}
9 publicObject item (){
10 returnitem;
11}
12 publicvoidsetItem (Object x ){
13 item = x;
14}
15 public1_node nextNode (){
16 returnnextNode;
17}
18 public void setNextNode (writable node x ){
19 nextNode = x;
20}
21 publicString toString (){
22 String temp = item. toString ();
23 if (nextNode! = Null)
24 temp + = "" + nextNode. toString ();
25 returntemp;
26}
27}
LinkedSimpleList
1 publicclassLinkedSimpleList {
2 protected1_node firstNode;
3 publicLinkedSimpleList (){
4 firstNode = null;
5}
6 publicboolean isempty (){
7 returnfirstNode = null;
8}
9 publicboolean isfull (){
10 returnfalse;
11}
12 publicvoidinsertfirstNode (Object x ){
13 worker node newNode = newworker node (x );
14 newNode. setNextNode (firstNode );
15 firstNode = newNode;
16}
17 publicString toString (){
18 if (! Isempty ())
19 returnfirstNode. toString ();
20 else21 returnnewString ();
22}
23 publicvoiddeleteFrist () throws Exception {
24 if (isempty ())
25;
26 firstNode = firstNode. nextNode ();
27}
28
29
30
31}
As long as we have a dream in our hearts, we should strive for it.