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);
......