java利用递归翻转链表

class Node{
	private String data;
	private Node next;
	public Node(String data) {
		this.data= data;
	}
	public void setNext(Node next) {
		this.next = next;
	}
	public Node getNext() {
		return this.next;
	}
	public void setData(String data) {
		this.data = data;
	}
	public String getData() {
		return this.data;
	}
	
	public void addNode(Node newNode) {
		if(this.next==null) {
			this.next= newNode;
		}else {
			this.next.addNode(newNode);
		}
	}
	
	public void fuck(String data) {
		if(this.data.equals("")) {
			this.data = data;
		}else {
			this.next.fuck(data);;
		}
	}
	
	public void change(Node node){
		if(this.next != null) {
			
			this.next.change(node);
			node.fuck(this.data);
			//System.out.println(this.getData());
		}else {
			//System.out.println(this.getData());
			node.fuck(this.data);
		}
	}
	
	public void printNode() {
		System.out.print(this.data);
		if(this.next!=null)
			this.next.printNode();
		else 
			System.out.println(" ");
	}
}

class Link{
	private Node root;
	private int len;
	public void add(String data) {
		Node newNode = new Node(data);
		if(this.root==null){
			this.root= newNode;
			this.len=1;
		}else {
			len+=1;
			this.root.addNode(newNode);
		}
	}
	
	public Link getRelad() {
		Link link_reladed= new Link();
		for (int i=0;i

你可能感兴趣的:(java)