-
Notifications
You must be signed in to change notification settings - Fork 0
/
liniear.java
116 lines (93 loc) · 2.57 KB
/
liniear.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication5;
import java.util.Scanner;
import java.lang.Math;
class HashNode{
int key;
int value;
HashNode(int k, int v){
this.key = k;
this.value = v;
}
};
class Table{
int tableSize = 10;
HashNode[] t;
Table(){
t = new HashNode[tableSize];
for(int i=0; i<tableSize; i++){
t[i] = null;
}
}
int hashFunction(int key){
return key % tableSize;
}
void insert(int key,int value){
int hash = hashFunction(key);
while(t[hash] != null && t[hash].key != -1){
hash = hashFunction(hash + 1);
}
t[hash] = new HashNode(key,value);
}
void search(int key){
int hash = hashFunction(key);
while(t[hash] != null && t[hash].key != key){
hash++;
}
if(t[hash] == null){
System.out.println("element not found");
}else{
System.out.println("found:"+hash);
}
}
void delete(int key){
int hash = hashFunction(key);
while(t[hash] != null && t[hash].key != key){
hash++;
}if(t[hash] == null){
System.out.println("element not found");
}else{
t[hash].key = -1;
}
}
void display(){
for(int i=0; i<tableSize; i++){
if(t[i] == null || t[i].key == -1){
System.out.println(i+" empty");
}else
System.out.println(t[i].value);
}
}
};
public class JavaApplication5 {
public static void main(String[] args) {
/*Table t = new Table();
t.insert(12, 60);
t.insert(10, 50);
t.delete(10);
t.insert(10, 50);
t.search(11);
t.display();*/
//Scanner s = new Scanner(System.in);
String st = "123";
int p = Integer.parseInt(st);
int j = 123;
String a = Integer.toBinaryString(j);
int bint = Integer.parseInt(a);
int q = 2,w =3;
double power = Math.pow(q, w);
//System.out.println(power);
String y = "Yasas";
int ascii = 0;
char temp;
for(int i=0; i<y.length(); i++){
temp = y.charAt(i);
ascii = ascii + (int)temp;
}
System.out.println(ascii);
}
}