class Main {
public static void main(String[] args) {
linkList link = new linkList();
for(int i = 1;i<101;i++){
link.add(i, i);
}
Node head = link.getHead();
Node p = head.next;
while(p !=null)
{
System.out.println(p.getData());
p=p.next;
}
}
}
class Node<T>{
T data;
Node<T> next;
public Node(Node<T>n){
next = n;
}
public Node(T obj, Node<T>n){
data = obj;
next =n;
}
public T getData(){
return data;
}
public Node<T> getNext(){
return next;
}
}
class linkList<T>{
private Node<T>head;
private int length;
public linkList(){
length = 0;
head = new Node<T>(null);
}
public Node<T>getHead(){
return head;
}
public boolean add(T obj, int pos){
if((pos<1||pos>length+1)){
System.out.println("pos值不合法");
return false;
}
int num = 1;
Node<T> p=head,q=head.next;
while(num<pos){
p=q;
q=q.next;
num++;
}
p.next = new Node<T>(obj,q);
length++;
return true;
}
public T delete(int pos){
int num = 1;
Node<T> p=head, q= head.next;
while(num < pos){
p=q;
q=q.next;
num++;
}
p.next = q.next;
length--;
return q.data;
}
public int find(T obj){
int num = 1;
Node<T>p=head.next;
while(p!=null){
if(p.data.equals(obj)==false){
p = p.next;
num++;
}
else break;
}
if(p==null)
return -1;
return num;
}
public T value(int pos){
if((pos<1||pos>length+1)){
System.out.println("pos值不合法");
return null;
}
int num=1;
Node<T> q=head.next;
while(num<pos){
q=q.next;
num++;
}
return q.data;
}
public boolean modify(T obj,int pos){
if((pos<1||pos>length+1)){
System.out.println("pos值不合法");
return false;
}
int num=1;
Node<T> q=head.next;
while(num<pos){
q=q.next;
num++;
}
q.data=obj; return true;
}
}