首页 > 代码库 > 找出单向链表中的倒数第k个结点

找出单向链表中的倒数第k个结点

import java.util.Scanner;

public class List {
	private Node first;
	private int N;
	class Node{
		int data;
		Node next;
	}
	//顺便复习一下链表
	public int size() { return N; }
	public boolean isEmpty() { return first==null; }
	
	public Node FindPrev(int pos){
		Node tmp=first;
		for(int i=1;i<=pos-1;i++)
			tmp=tmp.next;
		return tmp;
	}
	public boolean insert(int n,int pos){
		if(pos>n || pos<=0){
			System.out.println("illegal insert postion");
			return false;
		}
		Node tmp;
		tmp=FindPrev(pos);
		
		Node node=new Node();
		node.data=http://www.mamicode.com/n;>