Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.inql;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class AL6_3 {
- private Surname[] surnames;
- private Surname[] T;
- private final Surname del = new Surname(0,"DEL");
- public AL6_3(String path) throws IOException {
- this.surnames = readFile(path);
- }
- public Surname[] getSurnames() {
- return surnames;
- }
- public Surname[] readFile(String path) throws IOException {
- FileInputStream fileInputStream = new FileInputStream(path);
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
- Surname[] A;
- String currentLine;
- int arraySize = 0;
- while((currentLine = bufferedReader.readLine()) != null){
- arraySize++;
- }
- A = new Surname[arraySize];
- fileInputStream.getChannel().position(0);
- bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
- for(int i=0; i<arraySize; i++){
- currentLine = bufferedReader.readLine();
- Surname item = new Surname(Integer.parseInt(currentLine.split(" ")[0]),currentLine.split(" ")[1]);
- A[i] = item;
- }
- return A;
- }
- public void hashInsert(Surname surname){
- int i = 0;
- int j;
- do {
- j=hash(Utilities.wordToLong(surnames[i].getSurname(),111),T.length,i);
- if(T[j]==null || T[j].getSurname().equals("DEL")){
- T[j] = surname;
- return;
- }
- i++;
- }while(i<T.length);
- System.out.println("Błąd - brak miejsca w tablicy");
- }
- public int hashSearch(String surname){
- int i =0;
- int j =0;
- do {
- j=hash(Utilities.wordToLong(surname,111),T.length,i);
- if (T[j].getSurname().equals(surname))
- return j;
- i++;
- }while(T[j]!= null && i<T.length);
- return -1; //nie znaleziono wartości
- }
- public void hashDelete(String surname){
- int j = hashSearch(surname);
- if(j>=0)
- T[j] = del;
- else
- System.out.println("Brak takiej wartości w tablicy - nic nie zostało usunięte");
- }
- //adresowanie otwarte liniowe
- public int hash(long k, int m, int i){
- long result = (k % m +i)%m;
- return (int)result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement