javaд???????????
???????????? ???????[ 2014/2/12 9:48:53 ] ????????java ????
// ???????
public int getLength() {
Node<T> p = new Node<T>();
p = head;
int i = 0;
while (p != null) {
p = p.getNext();
i++;
}
return i;
}
// ???????λ??
public Node<T> changeList(int i?? int j) {
if (i <= 0 || j <= 0 || i >= getLength() || j >= getLength()) {
System.out.println("????????λ?ò??????");
return head;
}
if (i == j) {
return head;
}
Node<T> p = new Node<T>();
p = head;
Node<T> q = new Node<T>();
q = head;
Node<T> p_pre = new Node<T>();
p_pre = head;
Node<T> q_pre = new Node<T>();
q_pre = head;
for (int h = 2; h < Math.max(i?? j); h++) {
if (h < i) {
p_pre = p_pre.getNext();
}
if (h < j) {
q_pre = q_pre.getNext();
}
}
p = p_pre.getNext();
q = q_pre.getNext();
Node<T> v = new Node<T>();
v = q.getNext();
q.setNext(p.getNext());
p_pre.setNext(q);
p.setNext(v);
q_pre.setNext(p);
return head;
}
// ???????
public void printList() {
Node<T> p = new Node<T>();
p = head;
while (p != null) {
System.out.print(p.getData());
p = p.getNext();
}
System.out.print("
");
}
public Node<T> getHead() {
return head;
}
public void setHead(Node<T> head) {
this.head = head;
}
public static void main(String[] str) {
LinkList<Integer> link = new LinkList<Integer>();
Integer[] s = { 1?? 2?? 3?? 4?? 5?? 6?? 7?? 8?? 9 };
link.createList(s);
link.printList();
link.changeList(2?? 4);
link.printList();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11