package com.tqnsyh.liutong;
public class lb {
private int size;//链表大小
private Node head;//头链表
public lb(){
size=0;
head=null;
}
private class Node{
private Object data=null;
private Node next=null;
public Node(Object data){
this.data=data;
}
}
public void add(Object node){
Node p=new Node(node);
if(head==null){
head=p;//将这个指针指向头结点
size++;
}else{
p.next=head;
head=p;
size++;
}
}
public int getSize(){
return this.size;
}
public Object get(int index){
Node node=head;
//从头节点开始,依次向后查找
for(int i=0;i<index;i++)
node=node.next;
return node.data;
}
public void delte(int index){
Node node=head;
if(index==0)
head=node.next;
else{
for(int i=0;i<index-1;i++)
java 单链表实现
最新推荐文章于 2023-03-16 19:54:32 发布
本文详细探讨了如何使用Java编程语言实现单链表数据结构。从定义节点类到链表的基本操作,如插入、删除和遍历,逐一进行讲解,并通过实例代码加深理解。
摘要由CSDN通过智能技术生成