标签:style blog color ar for div log sp amp
public class Node { double data = 0; Node next = null; public Node(double data) { this.data = data; } public static Node reverse(Node head) { Node a = head; Node b = a.next; a.next = null; Node tmp = null; while (b != null) { tmp = b.next; b.next = a; a = b; b = tmp; } return a; } public static Node del(Node root, int k) { if (root == null) { return root; } if (k <= 0) { return root; } if (root.next == null && k == 1) { root = null; return root; } if (root.next == null && k != 1) { return root; } if(k==1){ root=root.next; return root; } int num = 1; Node tmp = root; Node p = tmp.next; num++; while (p != null) { if (k == num) { Node q = p.next; if (q != null) { tmp.next = q; return root; } else { tmp.next = null; } } tmp = p; p = p.next; num++; } return root; } public static void main(String[] args) { Node head = new Node(11); Node temp = head; for (int i = 0; i < 8; i++) { Node p = new Node(i); temp.next = p; temp = p; } head=del(head, 10); while(head!=null){ System.out.println(head.data); head=head.next; } } }
标签:style blog color ar for div log sp amp
原文地址:http://www.cnblogs.com/cclz/p/3942410.html