java集合list增删改查,java:手写MyLinkedList所有方法,增删改查

java:手写MyLinkedList所有方法,增删改查

package arrays.myArray;

public class MyLinkedList {

private int size = 0;

private Node1 head = null;

// 添加

public void add(Object obj) {

add(size, obj);

}

// 修改

public void add(int index, Object obj) {

if (null == head) {

head = new Node1(obj, null);

} else {

if (0 == index) {

head = new Node1(obj, head);

} else {

Node1 temp = head;

for (int i = 0; i < index - 1; i++) {

temp = temp.next;

}

temp.next = new Node1(obj, temp.next);

}

}

size++;

}

// 移除

public void remove(int index) {

if (0 == index) {

head = head.next;

} else {

Node1 temp = head;

for (int i = 0; i < index - 1; i++) {

temp = temp.next;

}

temp.next = temp.next.next;

}

size--;

}

// 查询

public Object get(int index) {

Node1 temp = head;

for (int i = 0; i < index; i++) {

temp = temp.next;

}

return temp.obj;

}

// 总长度

public int size() {

return size;

}

}

class Node1 {

Object obj;

Node1 next;

public Node1(Object obj, Node1 next) {

this.obj = obj;

this.next = next;

}

}

相关文档:

软件名称:图书管理工具

总体设计:

1.

命令行操作方式

2.

欢迎页面

---welcome to visit

software of book

management

Now is ...

& ......

1. java与平台无关。源代码由编译器编译为字节码(JVM可执行代码);解释器运行JVM字节码(翻译为机器码)即可得到输出结果。

字节码可在多个平台运行,不需要重新编译。

c编译器在编译时生成的代码是针对特定的硬件平台产生的。

2. java开发工具JDK。安装JDK时自带jre,就是java虚拟机。

jdk是Java开发工具包,包含了� ......

为什么说乱码是中国程序员无法避免的话题呢?这个首先要从编码机制上说起,大家都是中文和英文的编码格式不是一样,解码也是不一样的!如果中国的程序员不会遇到乱码,那么只有使用汉语编程。汉语编程是怎么回事我也不大清楚,应该是前年吧,我一朋友给我介绍汉语编程,怎么不错不错?当时因为学习忙没去关注这个,等我闲 ......

package arrays.file;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStreamRea ......

package arrays.myArray;

public class BinaryTree {

private Node root;

// 添加数据

public void add(int data) {

// 递归调用

if (null == root)

root = new Node(data, null, null);

else

addTree(root, data);

......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值