File tree 1 file changed +4
-18
lines changed
1 file changed +4
-18
lines changed Original file line number Diff line number Diff line change @@ -41,17 +41,12 @@ function HashTableSeparateChaining(){
41
41
//iterate linked list to find key/value
42
42
var current = table [ position ] . getHead ( ) ;
43
43
44
- while ( current . next ) {
44
+ do {
45
45
if ( current . element . key === key ) {
46
46
return current . element . value ;
47
47
}
48
48
current = current . next ;
49
- }
50
-
51
- //check in case first or last element
52
- if ( current . element . key === key ) {
53
- return current . element . value ;
54
- }
49
+ } while ( current ) ;
55
50
}
56
51
return undefined ;
57
52
} ;
@@ -65,7 +60,7 @@ function HashTableSeparateChaining(){
65
60
//iterate linked list to find key/value
66
61
var current = table [ position ] . getHead ( ) ;
67
62
68
- while ( current . next ) {
63
+ do {
69
64
if ( current . element . key === key ) {
70
65
table [ position ] . remove ( current . element ) ;
71
66
if ( table [ position ] . isEmpty ( ) ) {
@@ -74,16 +69,7 @@ function HashTableSeparateChaining(){
74
69
return true ;
75
70
}
76
71
current = current . next ;
77
- }
78
-
79
- //check in case first or last element
80
- if ( current . element . key === key ) {
81
- table [ position ] . remove ( current . element ) ;
82
- if ( table [ position ] . isEmpty ( ) ) {
83
- table [ position ] = undefined ;
84
- }
85
- return true ;
86
- }
72
+ } while ( current ) ;
87
73
}
88
74
89
75
return false ;
You can’t perform that action at this time.
0 commit comments