All pastes #493235 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-17 17:42 UTC
rendered paste body
public class BirdLinkedList
{
	// Birds for the list
	BirdNode head;
	BirdNode ref;
	BirdNode highest;
	BirdNode ref2;
	BirdNode previous = null;
	
	//Constructor
	public BirdLinkedList(BirdNode b)
	
	{
		head = null;
		head = b;
	}
	
	public Boolean find(BirdNode b)
	
	{
		Boolean found = false;
		ref = head;
		
		while(ref != null)
		{
			if(b.getBird().equals(ref.getBird()))
			
			{
				ref.setCount();
				found = true;
			}
			
			ref = ref.next;
		}
		
		return found;
		
	}
	
	public void insertFront(BirdNode b)
	{
		BirdNode front = new BirdNode(b.birds, b.count);
		front.next = head;
		head = front;
	}
	
	public void insertEnd(BirdNode b)
	{
		if (head == null)
		{
			head = b;
			return;
		}
		ref = head;
		
		while(ref.next != null)
		{
	
			ref = ref.next;
		}
		
		ref.next = b;
	}
	
	public void print()
	{
		ref = head;
		
		while(ref != null)
		{
			System.out.println(ref.toString());
			ref = ref.next;
		}
	}
	
	public BirdNode getHead()
	{
		return head;
	}
	
	public void remove(BirdNode b)
	{
		if(b.birds.equals(head.birds))
		{
			head = head.next;
			return;
		}
		
		ref = head;
		previous = ref;
		while(ref.next != null)
		{
			if(ref.next.birds.equals(b.birds))
			{
				previous = ref;
				ref = ref.next.next;
				previous.next = ref;
				return;
			}
			ref = ref.next;
		}
	}
	
}