[ create a new paste ] login | about

Link: http://codepad.org/8srgnIlu    [ raw code | output | fork ]

C, pasted on May 5:
class ListNode< T extends Comparable<T> > {
  private T data;
  private ListNode<T> nextNode;
  public ListNode(T object) {
    this(object,null);
  }
  public ListNode(T object,ListNode< T > node) {
    setData(object);
    setNext(node);
  }
  public T getData() {
    return data;
  }
  public ListNode<T> getNext() {
    return nextNode;
  }
  public void setData( T object ) {
    data = object;
  }
  public void setNext( ListNode< T > node ) {
    nextNode = node;
  }
}
public class OL< T extends Comparable<T> > {
  private ListNode<T> firstNode;
  private ListNode<T> lastNode;
  private String name;
  public OL(){
    this("ordered list");
  }
  public OL(String listName ){
    this.name = listName;
    firstNode = null;
    lastNode = null;
  }
  public void insert(T insertItem){
    if (isEmpty()){
      firstNode = new ListNode(insertItem);
      firstNode.setNext(lastNode);
    }else{
        ListNode<T> temp = firstNode;
        ListNode<T> before = null;
        ListNode<T> ins= new ListNode(insertItem);
        boolean isIns = false;
        do{
          if (temp.getData().compareTo(ins.getData()) > 0){
            //¥Ø«e­È >= ´¡¤J­È
            ins.setNext(temp);
            if (before == null){
              //¶}ÀY
              firstNode = ins;
            }else{
              //¤¤¶¡
              before.setNext(ins);
            }
            isIns = true;
            break;
          }
          before = temp;
          temp = temp.getNext();
        }while (temp != null);
        if (!isIns){
          //³Ì«á
          temp = firstNode;
          while (temp.getNext() != null){
            temp = temp.getNext();
          }
          temp.setNext(ins);
          lastNode = ins;
        }      
    }
  }
  public boolean isEmpty() {
    if (firstNode == null){
      return true;
    }else{
      return false;
    }
  }
  public T removeMin() {
    ListNode<T> target = firstNode;
    firstNode = target.getNext();
    return target.getData();
  }
  public T removeMax() {
    ListNode<T> target = lastNode;
    ListNode<T> temp = firstNode;
    ListNode<T> before = null;
    while (temp.getNext() != null){
      before = temp;
      temp = temp.getNext();
    }
    lastNode = before;
    before.setNext(null);
    return target.getData();
  }
  public void print() {
    ListNode<T> temp = firstNode;
    do{
        System.out.println(firstNode.getData());
        firstNode = firstNode.getNext();
    }while (!isEmpty());
    firstNode = temp;
    System.out.println();
  }
}
class EmptyListException extends RuntimeException {
  public EmptyListException() {
    this("List"); 
  }
  public EmptyListException(String name) {
    super( name + " is empty" );
  }
} 


Output:
1
2
3
Line 1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ListNode'
Line 24: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'class'
Line 107: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'EmptyListException'


Create a new paste based on this one


Comments: