導航:首頁 > 編程語言 > javatrie

javatrie

發布時間:2022-05-27 06:32:05

java按著字典順序排序

package com.play;

public class Decimal2Binary {
public static void main(String[] args)
{
String [] strArray = new String[]{"red","yellow","Black","Green"};
String t = null;
System.out.println("排序前");
for(String s : strArray)
System.out.print(s+"\t");
int i,j,k;
for(i=0;i<strArray.length-1; i++)
{
k=i;
for(j=i+1;j<strArray.length;j++)
{
Character c1 = Character.valueOf(strArray[j].charAt(0));
Character c2 = Character.valueOf(strArray[k].charAt(0));
if(c1.compareTo(c2)<0)
k=j;
}
if(i!=k)
{
t=strArray[i];
strArray[i]=strArray[k];
strArray[k]=t;
}
}
System.out.println("\n排序後:");
for(String s : strArray)
System.out.print(s+"\t");
}

}

② JAVA字典序排序

加入你把這些字元串放在一個 ArrayList<String> 裡面,叫做list
Arrays.sort(list);
就應該可以了
----
一行代碼能解決,你都不要。。你要普通排序。。
那不如你上網搜一個排序演算法貼上去。。很長的一段

③ 最好的手機JAVA字典!!

郎文字典!!!!
http://bbs.blueshow.net/read.php?tid=271639&keyword=%D7%D6%B5%E4
金山也還算可以
賽微隨身詞典
http://bbs.blueshow.net/read.php?tid=290958&keyword=%D7%D6%B5%E4
這個網站注冊免費,有很多好東西,游戲,刷機都可以找到

④ java字典怎麼使用

Map可以實現類似資料庫的功能。比如一個人的姓名和年齡信息你可以存在一個Map裡面,就像這樣: Map map = new HashMap(); map.put("張三", 40)

⑤ 二叉搜索樹java 京東金融java面試題 紅黑樹有什麼用java紅黑樹 java trie樹 快速

java8不是用紅黑樹來管理hashmap,而是在hash值相同的情況下(且重復數量大於8),用紅黑樹來管理數據。 紅黑樹相當於排序數據。可以自動的使用二分法進行定位。性能較高。
一般情況下,hash值做的比較好的話基本上用不到紅黑樹。

⑥ 求一個java排序的程序!字典順序的!

importjava.util.Arrays;
importjava.util.Scanner;


//必須實現Comparable介面
<Word>{

privatefinalStringword;

publicStringgetWord(){
returnword;
}

//構造器什麼的無視吧
publicWord(Stringword){
if(word==null)
thrownewNullPointerException("不可以創造空單詞!");
this.word=word;
}

//實現compareTo方法.主要的排序思路在這里
@Override
publicintcompareTo(Wordtarget){
if(target==null)
return1;

if(target.getWord().equalsIgnoreCase(getWord()))
return0;

char[]selfLetters=getWord().toLowerCase().toCharArray();
char[]targetLetters=target.getWord().toLowerCase().toCharArray();
intselfLength=selfLetters.length;
inttargeLength=targetLetters.length;
intminLength=Math.min(selfLength,targeLength);

for(intindex=0;index<minLength;index++){
if(selfLetters[index]>targetLetters[index]){
return1;
}
elseif(selfLetters[index]<targetLetters[index]){
return-1;
}
continue;
}

returnselfLength>targeLength?1:-1;
}

//重寫ToString方法以便列印輸出
@Override
publicStringtoString(){
returnword;
}

//主方法.用來查看效果
publicstaticvoidmain(String[]args){

intsize=5;//測試用的數組長度(單詞數);
//創造一個Word的數組用來保存輸入的單詞
Word[]words=newWord[size];
Scannersc=newScanner(System.in);
for(inti=0;i<size;i++)
{
System.out.println("請輸入第"+(i+1)+"個單詞");
words[i]=newWord(sc.nextLine());
}
sc.close();//關閉流

System.out.println("排序結果為:");

//使用Arrays.sort方法排序,sort對自動調用你的compareTo方法來比較
Arrays.sort(words);

//列印出結果
System.out.println(Arrays.toString(words));
}
}

這是我剛寫的。測試結果還可以。邏輯可能不是很嚴謹 不過作為作業應該應付足夠了

⑦ 鍵樹的代碼實現

一個標准Trie樹的Java實現如下:
import java.util.Arrays;
public class TrieNode {
public TrieNode() {
ptr = new TrieNode[BRANCH];
Arrays.fill(ptr, null);
}
public static final int BRANCH = 27;
public TrieNode[] ptr = null;
public int nptr = 0;
}
public class Trie {
public Trie() {
root = new TrieNode();
}
public void Insert(String key) {
TrieNode p = root;
for (int i = 0; i < key.length(); i++) {
int offset = key.charAt(i) - 'a';
if (p.ptr[offset] == null) {
p.ptr[offset] = new TrieNode();
p.nptr++;
}
p = p.ptr[offset];
}
}
public boolean Search(String key) {
TrieNode p = root;
for (int i = 0; i < key.length(); i++) {
int offset = key.charAt(i) - 'a';
if (p.ptr[offset] == null) {
return false;
}
p = p.ptr[offset];
}
return true;
}
private TrieNode root = null;
public static void main(String[] args) {
Trie trie = new Trie();
trie.Insert(liheyuan);
trie.Insert(liheyuan);
System.out.println(trie.Search(liheyuan));
}
}

⑧ 告訴我吧java按字典順序重新排列怎麼理解兩個不同的英文字母字元串,按照字元串中哪個字母為准排序

告訴我吧java按字典順序重新排列怎麼理解?兩個不同的英文字母字元串,按照字元串中哪個字母為准排序
菌別濁貢奪習登要宙拔喜涼宇講針

但願人長久,千里共嬋娟

⑨ java字典

http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/index.html
中文版的JAVA在線API查詢

⑩ Java裡面字典dictionary怎麼定義

Dictionary對象用於存儲數據關鍵字和條目對(即類似「key=value」的形式)。它可以存取任何形式的數據的條目。每個條目都與一個唯一的關鍵字相關聯。該關鍵字用來檢索單個條目,通常是整數或字元串,可以是除數組外的任何類型。

下面的代碼舉例說明了如何創建一個 Dictionary 對象:

Dim d '創建一個變數
Set d = CreateObject(Scripting.Dictionary)
d.Add "a", "Athens" '添加一些關鍵字和條目
d.Add "b", "Belgrade"
d.Add "c", "Cairo"

Dictionary常用的操作有Add(添加)、Remove(刪除)、Exists(檢查某個關鍵字是否在字典中);常用的屬性有Item(key)(獲取某個關鍵字對應的數據),等等。

差不多就有點象平時我們在演算法中提到的HashTable吧。

閱讀全文

與javatrie相關的資料

熱點內容
南京中興招收專科程序員嗎 瀏覽:297
代理商php源碼 瀏覽:983
蘋果手機怎麼解壓軟體app 瀏覽:650
游戲資源被編譯 瀏覽:152
代碼編譯後黑屏 瀏覽:8
程序員情侶寫真 瀏覽:505
python3孿生素數 瀏覽:36
計算楊輝三角Python 瀏覽:404
linux目錄重命名 瀏覽:196
演算法設計的最終形態是代碼 瀏覽:262
程序員社團招新橫幅 瀏覽:238
拖鞋解壓視頻大全 瀏覽:887
租伺服器主機鏈接軟體叫什麼 瀏覽:856
交叉編譯工具的linux版本號 瀏覽:156
python開發應用軟體 瀏覽:32
hdl綜合器與c編譯器的區別 瀏覽:899
編譯原理最左推導代碼 瀏覽:702
加密三 瀏覽:131
通過編譯鏈接後形成的可執行程序 瀏覽:680
怎麼用matlab編程 瀏覽:781