⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortedlist.java

📁 Program that uses a doc as database, and allows modifications at theses doc s
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package laforehash;import java.io.IOException;/** * * @author Usuario */public class SortedList {private Node root; // ref to first list item// ------------------------------------------------------------public SortedList (){    root = null;}public void insertList(Node node) {    int key = node.getId();    Node previous = null;     Node current = root;    while(current != null && key > current.getId())    {         previous = current;        current = current.getNext();     }    if(previous==null) // if beginning of list,    root = node; // first --> new link    else // not at beginning,    previous.setNext(node); // prev --> new link    node.setNext(current); // new link --> current   } // ------------------------------------------------------------public boolean isEmpty(){    Node current = root;    if(current == null)        return false;    else         return true;   }public boolean deleteList(int key) throws NullPointerException// delete link{ // (assumes non-emptyNode previous = null; // start at firstNode current = root;// until end of list,while(current != null && key != current.getId()){ // or key == current,previous = current;current = current.getNext(); // go to next link}if(previous==null) // if beginning of listroot = root.getNext(); // delete first linkelse // not at beginningprevious = current.getNext(); // delete currentreturn true;} // end deleteList()// ------------------------------------------------------------public Node find(int key) // find link{Node current = root; // start at first// until end of list,while(current != null && current.getId() <= key){ // or key too small,if(current.getId() == key) // is this the link?return current; // found it, return linkcurrent = current.getNext(); // go to next item}return null; // didn't find it} // end find()// ------------------------------------------------------------// ------------------------------------------------------------public Vagas findVagas(String formacao,int id) // find link{Vagas current = (Vagas)root; // start at first// until end of list,while(current != null && current.getId() <= id ){ // or key too small,if(current.getId() == id && current.getFormacao().equalsIgnoreCase(formacao)) return current; // found it, return linkcurrent = (Vagas)current.getNext(); // go to next item}return null; // didn't find it} // end find()// ------------------------------------------------------------public void displayVagas(int idemp){   System.out.print("Vagas disponiveis : ");Vagas current = (Vagas) root; // start at beginning of listwhile(current != null ) // until end of list,{                if(current.getId()== idemp){        current.displayVagas(); // print data    }current = (Vagas)current.getNext(); // move to next link}System.out.println("");}public void displayList(){Candidato current = (Candidato)root;     while(current != null)     {     current.displayLink();     current = (Candidato)current.getNext();     }    System.out.println("\n\n");}// ------------------------------------------------------------public boolean vagasEmpresa(SortedList listavagas,SortedList listaempresas) throws IOException{    System.out.println("Empresas com vagas disponiveis: ");        Vagas current = (Vagas) root; // start at beginning of list    if (listavagas.isEmpty())    {        Empresa empresa = new Empresa();            while(current != null) // until end of list,        {                    empresa = (Empresa)listaempresas.find(current.getId());        try        {            empresa.displayEmpresa();        }        catch (NullPointerException e){            System.out.println("\nCadastro Inexistente");        }               current = (Vagas)current.getNext(); // move to next link        }                   return true;    }        else            System.out.println("Não existe vagas");            return false;}public void displayListEsp(){System.out.print("Lista de Candidatos disponiveis : ");Candidato current = (Candidato) root; // start at beginning of listwhile(current != null ) // until end of list,{    if (current.getStatus().equalsIgnoreCase("livre"))    current.displayLink(); // print data    current = (Candidato)current.getNext(); // move to next link}System.out.println("");}// ------------------------------------------------------------public void displayList(String graduacao){System.out.print("Lista de Candidatos : ");Candidato current = (Candidato) root; // start at beginning of listwhile(current != null ) // until end of list,{    if(current.getGraduacao().equalsIgnoreCase(graduacao) && current.getStatus().equalsIgnoreCase("livre"))    current.displayLink(); // print data    current = (Candidato)current.getNext(); // move to next link}System.out.println("");   }  } // end class SortedList

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -