File tree Expand file tree Collapse file tree 1 file changed +4
-18
lines changed
Expand file tree Collapse file tree 1 file changed +4
-18
lines changed Original file line number Diff line number Diff line change @@ -41,17 +41,12 @@ function HashTableSeparateChaining(){
4141 //iterate linked list to find key/value
4242 var current = table [ position ] . getHead ( ) ;
4343
44- while ( current . next ) {
44+ do {
4545 if ( current . element . key === key ) {
4646 return current . element . value ;
4747 }
4848 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 ) ;
5550 }
5651 return undefined ;
5752 } ;
@@ -65,7 +60,7 @@ function HashTableSeparateChaining(){
6560 //iterate linked list to find key/value
6661 var current = table [ position ] . getHead ( ) ;
6762
68- while ( current . next ) {
63+ do {
6964 if ( current . element . key === key ) {
7065 table [ position ] . remove ( current . element ) ;
7166 if ( table [ position ] . isEmpty ( ) ) {
@@ -74,16 +69,7 @@ function HashTableSeparateChaining(){
7469 return true ;
7570 }
7671 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 ) ;
8773 }
8874
8975 return false ;
You can’t perform that action at this time.
0 commit comments