这篇文章将为大家详细讲解有关Java怎么实现顺序链表,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
public class SimpleQueue {
private Node head;
/**
* 添加节点 链表 尾插入法 需要与插入顺序保持一致
*/
public void addNode(Node node) {
if (null == head) {
head = node;
} else {
Node temp = head;
while (null != temp.next) {
temp = temp.next;
}
temp.next = node;
}
}
public Node popNode() {
Node returnVal = head;
head = head.next;
return returnVal;
}
}
关于“Java怎么实现顺序链表”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。