-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d79299
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="./style.css" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" | ||
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> | ||
<title>Autocomplete Application</title> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<div class="container"> | ||
<h1 class="top" style="text-transform:capitalize;text-align:center;padding-top:40px;">trie data structure algorithm</h1> | ||
</div> | ||
</header> | ||
|
||
<main> | ||
<div class="container top"> | ||
<div class="input-group mb-3"> | ||
<input type="text" class="form-control" placeholder="Type your Country Name" id="text-box"> | ||
</div> | ||
<ul id="list" class="list-group"> | ||
</ul> | ||
</div> | ||
</main> | ||
|
||
<script src="./trie.js"></script> | ||
<script src="./index.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//let words = "China,India,United States,Indonesia,Pakistan,Brazil,Nigeria,Bangladesh,Mexico,Japan,Ethiopia,Philippines,Egypt,Vietnam ,DR Congo,Turkey,Iran,Germany,Thailand,United Kingdom,France,Italy,Tanzania,South Africa,Myanmar,Kenya,South Korea,Colombia,Spain,Uganda,Argentina,Algeria,Sudan,Ukraine,Iraq,Afghanistan,Poland,Canada,Morocco,Saudi Arabia,Uzbekistan,Peru,Angola,Malaysia,Mozambique,Ghana,Yemen,Nepal,Venezuela,Madagascar,Cameroon,Côte d\'Ivoire,North Korea,Australia,Niger,Sri Lanka,Burkina Faso,Mali,Romania,Malawi,Chile,Kazakhstan,Zambia,Guatemala,Ecuador,Syria,Netherlands,Senegal,Cambodia,Chad,Somalia,Zimbabwe,Guinea,Rwanda,Benin,Burundi,Tunisia,Bolivia,Belgium,Haiti,Cuba,South,Dominican Republic,Czech Republic,Greece,Jordan,Portugal,Azerbaijan,Sweden,Honduras,United Arab Emirates,Hungary,Tajikistan,Belarus,Austria,Papua New Guinea,Serbia,Israel,Switzerland,Togo,Sierra Leone,Laos,Paraguay,Bulgaria,Libya,Lebanon,Nicaragua,Kyrgyzstan,El Salvador,Turkmenistan,Singapore,Denmark,Finland,Congo,Slovakia,Norway,Oman,State of Palestine,Costa Rica,Liberia,Ireland,Central African Republic,New Zealand,Mauritania,Panama,Kuwait,Croatia,Moldova,Georgia,Eritrea,Uruguay,Bosnia and Herzegovina,Mongolia,Armenia,Jamaica,Qatar,Albania ,Lithuania,Namibia,Gambia,Botswana,Gabon,Lesotho,North Macedonia,Slovenia,Guinea-Bissau,Latvia,Bahrain,Equatorial Guinea,Trinidad and Tobago,Estonia,Timor-Leste,Mauritius,Cyprus,Eswatini,Djibouti,Fiji,Comoros,Guyana,Bhutan,Solomon Islands,Montenegro,Luxembourg,Suriname,Cabo Verde,Micronesia,Maldives,Malta,Brunei,Belize,Bahamas,Iceland,Vanuatu,Barbados,Sao Tome & Principe,Samoa,Saint Lucia,Kiribati,Grenada,St. Vincent & Grenadines,Tonga,Seychelles,Antigua and Barbuda,Andorra,Dominica,Marshall Islands,Saint Kitts & Nevis,Monaco,Liechtenstein,San Marino,Palau,Tuvalu,Nauru,Holy See,"; | ||
|
||
const items = ["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia & Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica","Cote D Ivoire","Croatia","Cruise Ship","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kuwait","Kyrgyz Republic","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius","Mexico","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Namibia","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Norway","Oman","Pakistan","Palestine","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Pierre & Miquelon","Samoa","San Marino","Satellite","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain","Sri Lanka","St Kitts & Nevis","St Lucia","St Vincent","St. Lucia","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga","Trinidad & Tobago","Tunisia","Turkey","Turkmenistan","Turks & Caicos","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States of America","Uruguay","Uzbekistan","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"]; | ||
|
||
console.log(items) | ||
const root = new makeNode('\O'); | ||
for(const item of items) | ||
add(item.toLowerCase(),0,root) | ||
|
||
const text_box = document.getElementById('text-box') | ||
const list = document.getElementById('list') | ||
|
||
function handler(e) { | ||
const str = e.target.value; | ||
const predictions = search(str, 0, root); | ||
|
||
console.log(predictions); | ||
|
||
list.innerHTML = ""; | ||
for (const prediction of predictions) | ||
list.innerHTML += `<li class="list-group-item clickable" style="background:#009688;text-transform:capitalize;" onclick="handleClick(this)"><mark style='background:red;'>${str}</mark>${prediction.substring(str.length)}</li>`; | ||
|
||
} | ||
|
||
function handleClick(e){ | ||
text_box.value = e.innerText | ||
} | ||
|
||
//handler({target:{value:""}}) | ||
|
||
text_box.addEventListener("keyup",handler) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// const items = [ | ||
// "apple", | ||
// "apricot", | ||
// "banana", | ||
// "pear", | ||
// "guava", | ||
// "cherry", | ||
// "orange", | ||
// "pineapple", | ||
// "mango", | ||
// "grapes", | ||
// "blueberry", | ||
// "raspberry", | ||
// "melon", | ||
// "blackberry", | ||
// "plum", | ||
// "kiwi", | ||
// "peach", | ||
// "strawberry", | ||
// "avocado" | ||
// ]; | ||
|
||
// const root = new makeNode('\0'); | ||
// for (const item of items) | ||
// add(item, 0, root); | ||
|
||
// const text_box = document.getElementById("text-box"); | ||
// const list = document.getElementById("list"); | ||
|
||
// function handler(e) { | ||
// const str = e.target.value; | ||
// const predictions = search(str, 0, root); | ||
|
||
// console.log(predictions); | ||
|
||
// list.innerHTML = ""; | ||
// for (const prediction of predictions) | ||
// list.innerHTML += `<li class="list-group-item clickable" onclick="handleClick(this)"><b>${str}</b>${prediction.substring(str.length)}</li>`; | ||
|
||
// } | ||
|
||
// function handleClick(e) { | ||
// text_box.value = e.innerText; | ||
// } | ||
|
||
// handler({ target: { value: "" } }); | ||
|
||
|
||
// text_box.addEventListener("keyup", handler); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function makeNode(ch){ | ||
this.ch = ch | ||
this.isTarminal = false | ||
this.map = {} | ||
this.word = [] | ||
} | ||
|
||
function add(str, i, root){ | ||
if(i === str.length){ | ||
root.isTarminal = true | ||
return ; | ||
} | ||
|
||
if(!root.map[str[i]]){ | ||
root.map[str[i]] = new makeNode(str[i]) | ||
} | ||
|
||
root.word.push(str) | ||
add(str,i+1,root.map[str[i]]) | ||
} | ||
|
||
function search(str, i, root){ | ||
if(i === str.length) | ||
return root.word; | ||
|
||
if(!root.map[str[i]]) | ||
return ; | ||
return search(str , i+1,root.map[str[i]]) | ||
} |