All pastes #993031 Raw Edit

svein

public java v1 · immutable
#993031 ·published 2008-04-22 09:12 UTC
rendered paste body
public class LenkaListe {		//	Variables	private LenkaNode pointer;	private int count;		//	Constructor	public LenkaListe(){		pointer = null;		count = 0;	}		//	Add	public void add(int position, Object obj){		LenkaNode newNode = new LenkaNode(obj);		LenkaNode current, temp;				int index = 0;		if(pointer == null)			pointer = newNode;		else{			current = pointer;			if(position > 0){				while(pointer != null && index < position-1){					current = current.next;					index++;				}				temp  = current.next;				current.next = pointer;				pointer.next = temp;			}		}				count++;	}		//	Delete	public void delete(int position){		if(pointer == null)			return;		int index = 0;		LenkaNode current = pointer;				if(position > 0){			while(current.next != null && index < position-1){				current = current.next;				index++;			}			current.next = current.next.next;		}		else			pointer = pointer.next;		count--;	}		//	Get	public Object get(int position){		int index = 0;		LenkaNode current = pointer;		while(index != position-1){			current = current.next;			index++;		}		return current;	}		//	Make all null-pointer	public void makeNull(){		LenkaNode current = pointer;		while(count != 0){			if(current != null){				current = null;				current = current.next;				count--;			}			else				current = current.next;		}	}		//	LenkaNode-class	private class LenkaNode{		public Object obj;		public LenkaNode next;				public LenkaNode(Object obj){			this.obj = obj;			next = null;		}	}}