有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我怎样才能将我的四个完美的散列基本伪代码方法转换成可行的代码?

我试图弄明白如何将完美散列类中的4个基本伪代码方法转化为可操作的方法,最终将在PerfectHash类的主方法中使用。我知道我还没有创建这个类的实例,但是我会的

您知道,当您使用堆栈调用4个方法时,例如,您在方法中输入参数,但我的应用程序将能够获取用户输入的密钥,并在结构中对其进行插入、获取、删除或更新

我是否需要对这些方法投入更多的精力,或者伪代码现在就可以工作了吗?以下是我到目前为止所做的。我知道第一个类编译得很好,但是我在第二个类上遇到了问题,正如我上面已经指出的那样

public class PerfectHash
{

  private StadiumTickets[] data; 


  public boolean insert(StadiumTickets newStadiumTicket)
  {
      // the direct insert hashed algorithm 

       pseudoKey = preProcessing(targetKey); 
       ip = pseudoKey; // direct hashing function 

       // insert the new ticket
        data[ip] = newStadiumTicket.deepCopy(); 
  }

  public StadiumTickets fetch(String targetKey)
  {

    // the fetch algorithm 
    // access the primary storage area 

     pseudoKey = preprocessing(targetKey); 
     ip = pseudoKey; // direct hashing function 

    if(data[ip]== null)
     { 
         return null; 
     } 
     else
     {
        return data[ip].deepCopy(); 
     }
   } 

   public boolean delete(String targetKey)
   { 
      // the delete direct hashed algorithm 

      // access the primary storage area 

         pseudoKey = preprocessing(targetKey);

       ip = pseudoKey; // direct hashing function 

      if(data[ip]== null)
      { 
         return false; 
       } 
      else 
      { 
        data[ip]= null;                      
        return true; 
      }
    } 
    public boolean update(String targetKey, StadiumTickets newStadiumTicket)
    {
        // the update direct hashed algorithm 

       if(delete(targetKey) == false)
           return false; 
       else 
        {
           insert(newStadiumTicket) 
             return true;
         }
     }

}
import java.util.Scanner; 

public class StadiumTickets
{

     int ticketNumber; // keyfield

     String purchaserName; 


  public void input()
  {

     Scanner input= new Scanner(System.in);

      // key values ranges between 2000 to 100,000 


      System.out.print("Please enter a ticket number between 2000 to 100,000: "); 

      // a variable to hold the answer

       ticketNumber= input.nextInt(); 


        // error checking to make sure the user doesn't enter a key outside of the lower or upper ranges

       if(ticketNumber < 2000 && ticketNumber > 100000) 
        System.out.println("This number is not a valid entry to input into the structure.");
     }

  public StadiumTickets(int ticketNumber, String purchaserName)
  {

       this.ticketNumber= ticketNumber; 
       this.purchaserName= purchaserName; 
   } 



   public StadiumTickets deepCopy()
   { 

      StadiumTickets clone= new StadiumTickets(ticketNumber, purchaserName); 
       return clone; 
   }  
}

共 (0) 个答案