最后
针对以上面试题,小编已经把面试题+答案整理好了
面试专题
除了以上面试题+答案,小编同时还整理了微服务相关的实战文档也可以分享给大家学习
-
链接域
next
用来存放下一个节点的位置 ; -
变量p指向链表的头节点(首节点)的位置,从p出发能找到表中的任意节点。
代码实现《单向链表》
package com.daley.linkedlist;
import java.util.Iterator;
class Test{
public static void main(String[] args) {
MyLinkedList ml = new MyLinkedList<>();
ml.insert(“aa”);
ml.insert(“bb”);
ml.insert(“cc”);
ml.insert(0,“dd”);
for (Object s : ml){
System.out.println(s);
}
}
}
public class MyLinkedList implements Iterable {
//记录头结点
private Node head;
//记录链表的长度
private int N;
public MyLinkedList(){
this.head = new Node(null,null);
this.N = 0;
}
/**
- 定义节点类
*/
private class Node{
T item ; //存储数据
Node next; //下一个节点
public Node(T item, Node next) {
this.item = item;
this.next = next;
}
}
/**
- 清空链表
*/
public void clear(){
this.head = null;
this.N = 0;
}
/**
-
判断链表是否为空,是返回true,否返回false
-
@return
*/
public boolean isEmpty(){
return this.N == 0;
}
/**
-
获取链表中元素的个数
-
@return
*/
public int length(){
return this.N;
}
/**
-
读取并返回链中的第in