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;
}
}
Ïà¹ØÎĵµ£º
Ò»£ºÒª½â¾öµÄÎÊÌâ
ÎÒÃÇÔÚ³¢ÏÊ JDK1.5 µÄʱºò£¬ÏàÐŲ»ÉÙÈËÓöµ½¹ý Unsupported major.minor version 49.0
´íÎ󣬵±Ê±¶¨»áãȻ²»ÖªËù´ë¡£ÒòΪ¸Õ¿ªÊ¼ÄÇ»á¶ù£¬ÍøÉÏÓë´ËÏà¹ØµÄÖÐÎÄ×ÊÁÏ»¹²»¶à£¬ÏÖÔÚºÃÁË£¬ÍøÉÏÒ»ÕÒ¾ÍÖªµÀÊÇÈçºÎ½â¾ö£¬´ó¶à»á¸æËßÄãҪʹÓà JDK
1.4 ÖØÐ±àÒë¡£ÄÇôÖÁÓÚΪʲô£ ......
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);
......
package arrays.myArray;
public class MyArrayList {
private Object[] arrObj = new Object[3];
private int size = 0;
// ³¤¶È
public int size() {
return size;
}
// insert
public void add(Object obj) {
add(size,obj);
&nb ......