導航:首頁 > 編程語言 > java數據結構教程

java數據結構教程

發布時間:2023-02-05 23:26:06

『壹』 java 數據結構

大哥,你這是資料庫的問題.
你要是想用數據結構來解決的話也行,但是數據要是想長久保存的話,還是存入資料庫的好。
既然學java就要有面向對象的思想。
將學生看做一個對象,建立class student.將學號,姓名,成績做為屬性。學號與姓名用String存,成績可以用Hashtable來存,至於排序就 得把所以student對象的成績取出來進行排序

『貳』 數據結構JAVA編程求教

#include<stdio.h> /* EOF(=^Z或F6),NULL */

#define FALSE 0

#define OK 1

#define ERROR 0

typedef int Status; /* Status是函數的類型,其值是函數結果狀態代碼,如OK等 */

#define N 9 /* 數據元素個數 */

typedef char KeyType; /* 設關鍵字域為字元型 */

typedef struct /* 數據元素類型 */

{

KeyType key;

int weight;

}ElemType;

ElemType r[N]={{'A',1},{'B',1},{'C',2},{'D',5},{'E',3},

{'F',4},{'G',4},{'H',3},{'I',5}}; /* 數據元素(以教科書例9-1為例),全局變數 */

int sw[N+1]; /* 累計權值,全局變數 */

#define EQ(a,b) ((a)==(b))

#define LT(a,b) ((a)<(b))

typedef struct

{

ElemType *elem; /* 數據元素存儲空間基址,建表時按實際長度分配,0號單元留空 */

int length; /* 表長度 */

}SSTable;

Status Creat_Seq(SSTable *ST,int n)

{ /* 操作結果: 構造一個含n個數據元素的靜態順序查找表ST(數據來自全局數組r) */

int i;

(*ST).elem=(ElemType *)calloc(n+1,sizeof(ElemType)); /* 動態生成n個數據元素空間(0號單元不用) */

if(!(*ST).elem)

return ERROR;

for(i=1;i<=n;i++)

*((*ST).elem+i)=r[i-1]; /* 將全局數組r的值依次賦給ST */

(*ST).length=n;

return OK;

}

void Ascend(SSTable *ST)

{ /* 重建靜態查找表為按關鍵字非降序排序 */

int i,j,k;

for(i=1;i<(*ST).length;i++)

{

k=i;

(*ST).elem[0]=(*ST).elem[i]; /* 待比較值存[0]單元 */

for(j=i+1;j<=(*ST).length;j++)

if LT((*ST).elem[j].key,(*ST).elem[0].key)

{

k=j;

(*ST).elem[0]=(*ST).elem[j];

}

if(k!=i) /* 有更小的值則交換 */

{

(*ST).elem[k]=(*ST).elem[i];

(*ST).elem[i]=(*ST).elem[0];

}

}

}

Status Creat_Ord(SSTable *ST,int n)

{ /* 操作結果: 構造一個含n個數據元素的靜態按關鍵字非降序查找表ST */

/* 數據來自全局數組r */

Status f;

f=Creat_Seq(ST,n);

if(f)

Ascend(ST);

return f;

}

Status Traverse(SSTable ST,void(*Visit)(ElemType))

{ /* 初始條件: 靜態查找表ST存在,Visit()是對元素操作的應用函數 */

/* 操作結果: 按順序對ST的每個元素調用函數Visit()一次且僅一次。 */

/* 一旦Visit()失敗,則操作失敗 */

ElemType *p;

int i;

p=++ST.elem; /* p指向第一個元素 */

for(i=1;i<=ST.length;i++)

Visit(*p++);

return OK;

}

typedef ElemType TElemType;

typedef struct BiTNode

{

TElemType data;

struct BiTNode *lchild,*rchild; /* 左右孩子指針 */

}BiTNode,*BiTree;

Status SecondOptimal(BiTree *T, ElemType R[],int sw[],int low,int high)

{ /* 由有序表R[low..high]及其累計權值表sw(其中sw[0]==0)遞歸構造 */

/* 次優查找樹T。*/

int i,j;

double min,dw;

i=low;

min=fabs(sw[high]-sw[low]);

dw=sw[high]+sw[low-1];

for(j=low+1;j<=high;++j) /* 選擇最小的△Pi值 */

if(fabs(dw-sw[j]-sw[j-1])<min)

{

i=j;

min=fabs(dw-sw[j]-sw[j-1]);

}

*T=(BiTree)malloc(sizeof(BiTNode));

if(!*T)

return ERROR;

(*T)->data=R[i]; /* 生成結點 */

if(i==low)

(*T)->lchild=NULL; /* 左子樹空 */

else

SecondOptimal(&(*T)->lchild,R,sw,low,i-1); /* 構造左子樹 */

if(i==high)

(*T)->rchild=NULL; /* 右子樹空 */

else

SecondOptimal(&(*T)->rchild,R,sw,i+1,high); /* 構造右子樹 */

return OK;

}

void FindSW(int sw[],SSTable ST)

{ /* 按照有序表ST中各數據元素的Weight域求累計權值表sw */

int i;

sw[0]=0;

for(i=1;i<=ST.length;i++)

sw[i]=sw[i-1]+ST.elem[i].weight;

}

typedef BiTree SOSTree; /* 次優查找樹採用二叉鏈表的存儲結構 */

Status CreateSOSTree(SOSTree *T,SSTable ST)

{ /* 由有序表ST構造一棵次優查找樹T。ST的數據元素含有權域weight。*/

if(ST.length==0)

*T=NULL;

else

{

FindSW(sw,ST); /* 按照有序表ST中各數據元素的Weight域求累計權值表sw */

SecondOptimal(T,ST.elem,sw,1,ST.length);

}

return OK;

}

Status Search_SOSTree(SOSTree *T,KeyType key)

{ /* 在次優查找樹T中查找關鍵字等於key的元素。找到則返回OK,否則返回FALSE */

while(*T) /* T非空 */

if((*T)->data.key==key)

return OK;

else if((*T)->data.key>key)

*T=(*T)->lchild;

else

*T=(*T)->rchild;

return FALSE; /* 順序表中不存在待查元素 */

}


void print(ElemType c) /* Traverse()調用的函數 */

{

printf("(%c %d) ",c.key,c.weight);

}

void main()

{

SSTable st;

SOSTree t;

Status i;

KeyType s;

Creat_Ord(&st,N); /* 由全局數組產生非降序靜態查找表st */

Traverse(st,print);

CreateSOSTree(&t,st); /* 由有序表構造一棵次優查找樹 */

printf(" 請輸入待查找的字元: ");

scanf("%c",&s);

i=Search_SOSTree(&t,s);

if(i)

printf("%c的權值是%d ",s,t->data.weight);

else

printf("表中不存在此字元 ");

}

運行結果:

這個是數據結構上的一個源碼,你用這個自己改一改試試吧

『叄』 JAVA數據結構

public class CallNotes {

String name;
String phoneNumber;
static Map<String,String> noteMap=null;
static List<CallLog> logList=null;

CallNotes(){
this.noteMap = new HashMap<String,String>();
this.logList = new ArrayList<CallLog>();
}

void addRecord(String name,String number){
noteMap.put(name,number);
}
void removeRecord(String name){
noteMap.remove(name);
}

String searchPhoneNumber(String name){
String number=null;
number = noteMap.get(name);
logList.add(new CallLog(name, number, new Date()));
return number;
}
void outputCallLog(CallLog log){
if(log==null) return ;
log.outputLog();
}

class CallLog{
String name;
String number;
Date date;
CallLog(String name,String num,Date date) {
this.name=name;
this.number=num;
this.date=date;
}
void outputLog(){
System.out.println("name:"+this.name);
System.out.println("number:"+this.number);
System.out.println("date:"+this.date);
}
}
}
用HashMap實現可以嗎?

『肆』 求JAVA.數據結構.演算法學習視頻百度雲。

《數據結構課程精講教案合集-復旦大學(共計1061頁).pdf 》網路網盤免費資源下載

鏈接: https://pan..com/s/15uwjtHgKKzZdheWFQC21pQ

?pwd=abzc 提取碼: abzc

『伍』 數據結構 java

應該是char
public void outprint( ) { // 本方法調用後輸出的結果是什麼?
Queue Q=new Queue();
String x=」e」 , y=」c」;
Q. enqueue (「h」);
Q. enqueue (「r」);
Q. enqueue (y); //到此,Q中元素:'h'、'r'、'c'
x=(String)Q. dequeue (); //'h'出去,x='h',Q中元素:'r'、'c';
Q. enqueue (x); //x進去,Q中元素:'r'、'c'、'h
x=(String)Q. dequeue (); //'r'出去,x='r',Q中元素:'c'、'h'
Q. enqueue (「a」); //'a'進去,Q中元素:'c'、'h'、'a'
while(!Q.isEmpty()){
y =(String)Q. dequeue ();
System.out.print(y); } //所以,while循環應列印出cha
System.out.println(x); //x='r',最終輸出char
}

『陸』 java如何表示數據結構

一、List介面,有序的Collection介面,精確地控制每個元素插入的位置,允許有相同的元素
1.鏈表,LinkedList實現了List介面,允許null元素,提供了get()、remove()、insert()方法。
[java] view plain
public void add() {
LinkedList List = new LinkedList();
List.add("link1");
List.add("link2");
List.add("link3");
Iterator it = List.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
it.remove();
Iterator it1 = List.iterator();
for (int i = 0; i < List.size(); i++) {
System.out.println(it1.next());
}
}

2.數組列表,ArrayList,可以動態變化容量的數組,數組列表中存放Object類型,在數組列表中存放的對象類型,以其原型的父類代替,提取其中的元素時要進行類型轉換
[java] view plain
public static void main(String[] args)
{
ArrayList al=new ArrayList();
al.add("name");
al.add("value");
al.add("number");
for(int i=0;i<al.size();i++)
{
System.out.println(al.get(i));
}
}

二、Set介面,不包含重復元素的Collection介面
1.散列集,HashSet,實現了Set介面,非線性同步與鏈表和數組列表幾乎類似,處理時鏈表進行數據處理花費時間更短,處理大數據時通常使用散列集
[java] view plain
public static void main(String[] args)
{
long time=0;
HashSet hs=new HashSet();
ArrayList al=new ArrayList();
long starttime=System.currentTimeMillis();
for(int i=0;i<10000;i++)
{
hs.add(new Integer(i));
}
System.out.println(System.currentTimeMillis()-starttime);
for(int i=0;i<10000;i++)
{
al.add(new Integer(i));
}
System.out.println(System.currentTimeMillis()-starttime);
}

2.樹集,TreeSet,實現了Set介面,實現了排序功能,集合中的元素默認按升序排列元素。
三、Map介面,沒有繼承Collection介面,其提供key到value的映射,Map中不能包含相同的key,每個key只能映射一個value。
1.散列表類,HashTable,繼承了Map介面,非空(non-null)的對象都可作為key或value,特點:無序的可以快速查找特定的元素

[java] view plain
public static void TableTest(){
Hashtable ht = new Hashtable();
ht.put("key1", "value1");
ht.put("key2", "value2");
String value1=(String)ht.get("key2");
System.out.println(value1);
}

2.散列映射類,HashMap,與HashTable類似,HashMap是非同步的,且允許null

[java] view plain
public static void Maptest(){
Map<string string=""> map=new HashMap<string string="">();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
for(Map.Entry<string string=""> entry:map.entrySet()){
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
String value1=(String)map.get("key1");
System.out.println(value1);
}
</string></string></string>

『柒』 郝斌老師的java 數據結構視頻教程

10《數據結構》【005】

鏈接:https://pan..com/s/1jHDInT5qZOnvIZPjyVHOBQ

提取碼:2r91 復制這段內容後打開網路網盤手機APP,操作更方便哦!

若資源有問題歡迎追問~

『捌』 求一本用Java語言描述的數據結構與演算法的入門書籍

1,數據結構與演算法分析(Java版高等院校計算機應用技術系列教材) 王世民
清華大學出版社 (2005-07出版)
這本書最合適了,原價才22元。
http://www.amazon.cn/mn/detailApp?qid=1204378864&ref=SR&sr=1-8&uid=168-3893319-5388224&prodid=zjbk191118

2,
數據結構--Java語言描述(高等學校教材計算機科學與技術) 朱戰立
清華大學出版社 (2005-12出版)
這本沒有上一本好,開始講了太多無關的東西。原價為25元。
http://www.amazon.cn/mn/detailApp?qid=1204378864&ref=SR&sr=1-9&uid=168-3893319-5388224&prodid=zjbk235595

以上兩本都還可以,比較淺顯易懂,還有一些別的書,但都不太適合入門。

『玖』 java數據結構書籍推薦

1. 入門級

針對剛入門的同學,建議不要急著去看那些經典書,像《演算法導論》、《演算法》這些比較經典、權威的書。雖然書很好,但看起來很費勁,如果看不完,效果會很不好。所以建議先看兩本入門級的趣味書:

閱讀全文

與java數據結構教程相關的資料

熱點內容
麻將機命令 瀏覽:868
軟體安全與編譯器體系結構書籍 瀏覽:915
壓縮空氣釋放的風速變化 瀏覽:85
linuxjdk安裝路徑rpm 瀏覽:256
簡歷上的程序員面試 瀏覽:629
linuxcurl參數 瀏覽:772
編輯貓少兒編程靠譜嗎 瀏覽:840
阿里java編程規范 瀏覽:158
哪個網有編程課 瀏覽:402
程序員初學者如何自學編程 瀏覽:406
手機在線解壓縮 瀏覽:136
編譯器分配不可用地址 瀏覽:358
內網郵件伺服器是什麼 瀏覽:139
u盤加密電腦不認識了 瀏覽:402
壓縮機粗管是迴流管 瀏覽:280
javastring逗號 瀏覽:283
程序員寫什麼類型代碼 瀏覽:372
怎麼和俄羅斯人交朋友app 瀏覽:537
ndz文件壓縮 瀏覽:603
android序列化和反序列化 瀏覽:354