guyanqing hai 10 meses
pai
achega
266fbd9532

+ 95 - 0
src/main/java/com/sf/javase/day14/MyLinkedList.java

@@ -0,0 +1,95 @@
+package com.sf.javase.day14;
+
+import org.junit.jupiter.api.Test;
+import org.omg.CORBA.portable.ValueOutputStream;
+
+import java.util.StringJoiner;
+
+public class MyLinkedList {
+    //头节点
+     Node head;
+    class  Node{
+       int data;
+       Node next;
+
+        public Node(int data) {
+            this.data = data;
+            this.next = null;
+        }
+    }
+
+    //添加元素   添加首元素
+    public void push(int new_data){
+        Node new_node = new Node(new_data);
+        new_node.next = head;
+        head = new_node;
+    }
+
+
+    //添加中间元素
+    public void insertAfter(Node prev_node,int new_date){
+        if(prev_node == null){
+            throw new RuntimeException("头节点不能为空~");
+        }
+        Node new_node = new Node(new_date);
+        new_node.next = prev_node.next;
+        prev_node.next = new_node;
+    }
+
+    //添加元素  -- 尾部
+    public void append(int new_date){
+        Node new_node = new Node(new_date);
+        if(head == null){
+          head =  new Node(new_date);
+          return;
+        }
+        new_node.next = null;
+       Node last = head;
+        while (last.next !=null){
+            last = last.next;
+        }
+        last.next = new_node;
+//        return;
+    }
+
+
+    //删除节点
+    public void  deleteNode(int key){
+        Node temp = head;
+        Node pre = null;
+        if(temp !=null  && temp.data == key){
+            head = temp.next;
+        }
+        while (temp !=null && temp.data != key){
+         pre = temp;
+         temp = temp.next;
+        }
+         if(temp == null){
+             return;
+         }
+        pre.next = temp.next;
+    }
+
+   //  打印链表数据
+    public void printList(){
+      Node node = head;StringJoiner joiner = new StringJoiner(",","[ "," ]");
+      while (node!=null){
+//          System.out.print(node.data + "  ");
+          joiner.add(node.data+"");
+          node = node.next;
+      }
+        System.out.println(joiner);
+    }
+
+
+    public static void main(String[] args) {
+        MyLinkedList myLinkedList = new MyLinkedList();
+        myLinkedList.push(12);
+        myLinkedList.append(14);
+        myLinkedList.append(15);
+        myLinkedList.append(15);
+        myLinkedList.append(116);
+        myLinkedList.insertAfter(myLinkedList.head.next,16);
+        myLinkedList.printList();
+    }
+}

+ 43 - 0
src/main/java/com/sf/javase/day14/T.java

@@ -0,0 +1,43 @@
+package com.sf.javase.day14;
+
+/**
+ * list  - linkedList
+ */
+
+import org.junit.jupiter.api.Test;
+
+import java.util.*;
+
+public class T {
+    @Test
+    public void t1(){
+        List<Object> list = new ArrayList<>();
+        LinkedList<Object> linkedList = new LinkedList<>();
+        list.add(null);
+        linkedList.add(null);
+        System.out.println(list);
+        System.out.println(linkedList);
+        linkedList.addFirst(22);
+//        linkedList
+    }
+
+    /**
+     * Vector
+     */
+    @Test
+    public void t2(){
+        Vector<String> vector = new Vector<>();
+        vector.add("qw");
+        vector.removeElement("q");
+    }
+
+
+    @Test
+    public void t3(){
+        Set<Integer> set = new HashSet();
+        set.add(1);
+//        LinkedHashSet   //自己练习
+//        TreeSet        //自己练习
+    }
+
+}

BIN=BIN
target/classes/com/sf/javase/day14/MyLinkedList$Node.class


BIN=BIN
target/classes/com/sf/javase/day14/MyLinkedList.class


BIN=BIN
target/classes/com/sf/javase/day14/T.class