
public class LinkedList<T> {
	
	private Node<T> head=null;
	private int size;

	public void print(){
		Node<T> pos=head;
		System.out.println(head);
		if(size==1){
			System.out.println(pos.toString());
		}
		else{
			pos=pos.getNext();
			while(pos != head){
				System.out.println(pos.toString());
				pos=pos.getNext();
			}
		}
	}
	
	public void printReverse(){
		int count=size;
		for (int i = 0; i < size; i++) {
			printRev(--count);
		}
		
		
	}

	public boolean add(T data){
		Node<T> newNode = new Node<>(data);
		Node<T> pos= head;
		
		if(size==0){
			head=newNode;
			newNode=head;
			++size;
			
			return true;
		}
		
		if(size==1){
			head.setNext(newNode);
			newNode.setNext(head);
			++size;
			return true;
		}
		
		while(pos.getNext() != head){
			pos=pos.getNext();
		}
		pos.setNext(newNode);
		newNode.setNext(head);
		++size;
		return true;

	}
	
	private void printRev(int count){
		Node<T> pos=head;
		
		for(int i=0;i<count;++i)
			pos=pos.getNext();
		
		System.out.println(pos.toString());
	}
 

}
