Hey there! Sign in to join this conversationNew here? Join for free

How can Implement a perfect hashed data structure using the four basic operations? watch

    • Thread Starter
    Offline

    1
    ReputationRep:
    Here's what I have so far, but I am struggling with translating the pseudocode into real code for each of four methods. Any books or suggestions on how I can get it to work? To add content to this application, I am working on trying to create a perfect hashed data structure and implement its four basic operation methods which should be called inside a main method of the perfect hash class.The ticket number will be the key field and the nodes will also store the purchaser's name.


    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: "i;

    // 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;
    }
    }



    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;
    }
    }

    }
 
 
 
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.