explane the java code below: LPHTb1.java import java.util.Scanner; class LPHTbl {     private int currSz, maxSz;     private String[] keyzzz;     private String[] values;     public LPHTbl(int cap) {         currSz = 0;         maxSz = cap;         keyzzz = new String[maxSz];         values = new String[maxSz];     }     public void chckEmpty() {

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

can you explane the java code below:

LPHTb1.java

import java.util.Scanner;
class LPHTbl {
    private int currSz, maxSz;
    private String[] keyzzz;
    private String[] values;

    public LPHTbl(int cap) {
        currSz = 0;
        maxSz = cap;
        keyzzz = new String[maxSz];
        values = new String[maxSz];
    }

    public void chckEmpty() {
        currSz = 0;
        keyzzz = new String[maxSz];
        values = new String[maxSz];
    }

    public int getSz() {
        return currSz;
    }

    public boolean chckFull() {
        return currSz == maxSz;
    }

    public boolean empty() {
        return getSz() == 0;
    }

    public boolean cntn(String keys) {
        return get(keys) != null;
    }

    private int hashing(String keys) {
        return keys.hashCode() % maxSz;
    }

    public void ins(String keys, String val) {
        int tempo = hashing(keys);
        int uu = tempo;
        do {
            if (keyzzz[uu] == null) {
                keyzzz[uu] = keys;
                values[uu] = val;
                currSz++;
                return;
            }
            if (keyzzz[uu].equals(keys)) {
                values[uu] = val;
                return;
            }
            uu = (uu + 1) % maxSz;
        } while (uu != tempo);
    }

    public String get(String keys) {
        int uu = hashing(keys);
        while (keyzzz[uu] != null) {
            if (keyzzz[uu].equals(keys))
                return values[uu];
            uu = (uu + 1) % maxSz;
        }
        return null;
    }

    public void remove(String keys) {
        if (!cntn(keys))
            return;

        int uu = hashing(keys);
        while (!keys.equals(keyzzz[uu]))
            uu = (uu + 1) % maxSz;
        keyzzz[uu] = values[uu] = null;
        for (uu = (uu + 1) % maxSz; keyzzz[uu] != null; uu = (uu + 1) % maxSz) {
            String tmp1 = keyzzz[uu], tmp2 = values[uu];
            keyzzz[uu] = values[uu] = null;
            currSz--;
            ins(tmp1, tmp2);
        }
        currSz--;
    }

    public void printHashTable() {
        System.out.println("\nHash Table: ");
        for (int uu = 0; uu < maxSz; uu++)
            if (keyzzz[uu] != null)
                System.out.println(keyzzz[uu] + " " + values[uu]);
        System.out.println();
    }
}

public class LinearProbingHashTableTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Hash Table Test\n\n");
        System.out.println("Enter size");
        LPHTbl tbl = new LPHTbl(sc.nextInt());

        char choi = 0;
        do {
            System.out.println("\nHash Table Operations\n");
            System.out.println("1. insert ");
            System.out.println("2. remove");
            System.out.println("3. get");
            System.out.println("4. clear");
            System.out.println("5. size");

            int ch = sc.nextInt();
            switch (ch) {
            case 1:
                System.out.println("Enter keys and value");
                tbl.ins(sc.next(), sc.next());
                break;
            case 2:
                System.out.println("Enter keys");
                tbl.remove(sc.next());
                break;
            case 3:
                System.out.println("Enter keys");
                System.out.println("Value = " + tbl.get(sc.next()));
                break;
            case 4:
                tbl.chckEmpty();
                System.out.println("Hash Table Cleared\n");
                break;
            case 5:
                System.out.println("Size = " + tbl.getSz());
                break;
            default:
                System.out.println("Wrong Entry \n ");
                break;
            }
            tbl.printHashTable();

            System.out.println("\nDo you want to continue (Type y or n) \n");
            ch = sc.next().charAt(0);
        } while (choi != 'Y' || choi != 'y');
    }
}

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY