tray - public class tray cfw private block head private...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
public class tray { private block head; private block tail; private long hashcode; public tray(){ hashcode=0; head=null; tail=null; } public tray(tray t){ hashcode=t.hashcode; if(t.getHead()==null){ head=null; tail=null; }else{ head=new block(t.getHead().getVal()); tail=head; block iter=head; for(block i=t.getHead().getNext(); i!=null; i=i.getNext()){ iter.setNext(new block(i.getVal())); iter=iter.getNext(); tail=iter; } } } public long getHashCode(){ return hashcode; } public void add(block b){ hashcode+=b.hashcode(); if(head==null){ head=b; tail=b; } else if(lessThan(b, head)){ b.setNext(head); head=b; } else if(!lessThan(b, tail)){ tail.setNext(b); tail=b; } else{ for(block i=head; i.getNext()!=null; i=i.getNext()){ if(lessThan(b, i.getNext())){ b.setNext(i.getNext()); i.setNext(b); return; } } } } private static boolean lessThan(block a, block b){ if(a.getRow()<b.getRow()) return true;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
else if(a.getRow()==b.getRow()){ if(a.getCol()<b.getCol()) return true; else return false; } else
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/12/2011 for the course CS 61bl taught by Professor Courney during the Spring '11 term at Berkeley.

Page1 / 3

tray - public class tray cfw private block head private...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online