当前位置:首页 » 编程语言 » java版的数据结构

java版的数据结构

发布时间: 2022-07-26 18:34:16

㈠ 什么是java数据结构

数据结构不是JAVA专有.
应该说数据结构是独立于某个具体语言的.
单从JAVA来说,就是用JAVA语言的语法方式,来表达一个对象应该具有什么样的表现形式.

㈡ Java中的数据结构有哪些

List相关:包括ArrayList(基于数组),LinkedList(基于链表),Stack等
Map相关:包括TreeMap,HashMap等
Set相关:包括TreeSet,HashSet等
总的来说,常见数据结构Java集合框架中都有实现。

㈢ java数据结构

首先明确,带权路径长度WPL最小的二叉树称作最优二叉树或哈夫曼树


那么比如说有4个节点,分别带权7,5,2,4如下ab两图

WPLa=7*2+5*2+2*2+4*2=36

WPLb=7*1+5*2+2*3+4*3=35

WPL=30*2+5*5*4+8*4*15*3+15*2+27*2=

不算了 口算不行... 看上式也知道你出现的概率越大,相当于基地越大,就给你乘个小的代价,必然是最优的。

㈣ java 数据结构

<数据结构与java集合框架>第二版中就有
自己可以查!

当然为了分在麻烦也要写:
//Queue.java
import java.util.*;

public class Queue {

protected LinkedList list;

// Postcondition: this Queue object has been initialized.
public Queue() {

list = new LinkedList();

} // default constructor

// Postcondition: the number of elements in this Queue object has been
// returned.
public int size() {

return list.size();

} // method size

// Postcondition: true has been returned if this Queue object has no
// elements. Otherwise, false has been returned.
public boolean isEmpty() {

return list.isEmpty();

} // method isEmpty

// Postconditon: A of element has been inserted at the back of this
// Queue object. The averageTime (n) is constant and
// worstTime (n) is O (n).
public void enqueue(Object element) {

list.addLast(element);

} // method enqueue

// Precondition: this Queue object is not empty. Otherwise,
// NoSuchElementException will be thrown.
// Postcondition: The element that was at the front of this Queue object -
// just before this method was called -- has been removed
// from this Queue object and returned.
public Object dequeue() {

return list.removeFirst();

} // method dequeue

// Precondition: this Queue object is not empty. Otherwise,
// NoSuchElementException will be thrown.
// Postcondition: the element at index 0 in this Queue object has been
// returned.
public Object front() {

return list.getFirst();

} // method front

} // Queue class

//Car.java
public class Car {

protected int arrivalTime;

// The Car has been constructed.
public Car() {
}

// The car has been constructed from the arrival time.
public Car(int nextArrivalTime) {

arrivalTime = nextArrivalTime;

} // constructor with int parameter

// Postcondition: The arrival time of the Car has been returned.
public int getArrivalTime() {

return arrivalTime;

} // method getArrivalTime

} // class Car

//CarWash.java
import general.GUI;
import general.Process;

import java.util.*;

public class CarWash implements Process {

protected final String PROMPT = "\nIn the Input line, please enter "
+ "the next arrival time. The sentinel is ";

protected final int ILLEGAL_INPUT = -1;

protected final int SENTINEL = 999;

protected final int INFINITY = 10000; // indicates no car being washed

protected final int MAX_SIZE = 5; // maximum cars allowed in carQueue

protected final int WASH_TIME = 10; // minutes to wash one car

protected GUI gui;

protected Queue carQueue;

protected int currentTime, nextDepartureTime, numberOfCars,
sumOfWaitingTimes;

// The CarWash has been initialized.
public CarWash() {

gui = new GUI(this);
carQueue = new Queue();
currentTime = 0;
numberOfCars = 0;
sumOfWaitingTimes = 0;
nextDepartureTime = INFINITY;
gui.println(PROMPT + SENTINEL);

} // constructor

// Postcondition: The next arrival time, in the string s, has been
// processed.
public void processInput(String s) {

int nextArrivalTime;

gui.println(s);
nextArrivalTime = parseOK(s);
if (nextArrivalTime != ILLEGAL_INPUT)
if (nextArrivalTime != SENTINEL) {

while (nextArrivalTime >= nextDepartureTime)
processDeparture();
processArrival(nextArrivalTime);
gui.println(PROMPT + SENTINEL);

} // processing next arrival
else { // process any cars remaining on the queue:

while (nextDepartureTime < INFINITY)
processDeparture();
printResult();
gui.freeze();

} // processing cars still on queue after last arrival
else
gui.println(PROMPT + SENTINEL);

} // processInput

// Postcondition: if a legal value for next arrival time has been
// obtained from the Input line, that value has been
// returned. Otherwise, ILLEGAL_INPUT has been returned.
protected int parseOK(String s) {

final String INTEGER_NEEDED = "\nThe input line should consist of an integer.";

StringTokenizer tokens = new StringTokenizer(s);

try {

return Integer.parseInt(tokens.nextToken());

} // try
catch (NoSuchElementException e) {

gui.println(e + INTEGER_NEEDED);

} // catch not enough input
catch (NumberFormatException e) {

gui.println(e + INTEGER_NEEDED);

} // input not in integer form
return ILLEGAL_INPUT;

} // method parseOK

// Postcondition: A car has arrived and has either been turned away --
// if the Queue was full before this message was sent --
// or has entered the car wash.
protected void processArrival(int nextArrivalTime) {

final String OVERFLOW = "Overflow";

currentTime = nextArrivalTime;
if (carQueue.size() == MAX_SIZE)
gui.print(OVERFLOW);
else {

numberOfCars++;
if (nextDepartureTime == INFINITY)
nextDepartureTime = currentTime + WASH_TIME;
else
carQueue.enqueue(new Car(nextArrivalTime));

} // not an overflow

} // method processArrival

// Postcondition: A car has finished getting washed.
protected void processDeparture() {

int arrivalTime, waitingTime;

currentTime = nextDepartureTime;
if (!carQueue.isEmpty()) {

Car car = (Car) carQueue.dequeue();
arrivalTime = car.getArrivalTime();
waitingTime = currentTime - arrivalTime;
sumOfWaitingTimes += waitingTime;
nextDepartureTime = currentTime + WASH_TIME;

} // carQueue was not empty
else
nextDepartureTime = INFINITY;

} // method processDeparture

// Postcondition: The average waiting time, or an errro message,
// has been printed.
protected void printResult() {

final String NO_CARS_MESSAGE = "There were no cars in the car wash.";
final String AVERAGE_WAITING_TIME_MESSAGE = "\n\nThe average waiting time, in minutes, was ";
final String CLOSE_WINDOW_PROMPT = "\nThe execution of the project "
+ "is finished. Please close this window when you want to.";

if (numberOfCars == 0)
gui.println(NO_CARS_MESSAGE);
else
gui.println(AVERAGE_WAITING_TIME_MESSAGE
+ ((double) sumOfWaitingTimes / numberOfCars));
gui.print(CLOSE_WINDOW_PROMPT);

} // method printResult

} // class CarWash

//CarWashMain .java
public class CarWashMain {

public static void main(String[] args) {

CarWash carWash = new CarWash();

} // method main

} // class CarWashMain

㈤ JAVA数据结构哪些

主要是3种接口:List Set Map
List:ArrayList,LinkedList:顺序表ArrayList,链表LinkedList,堆栈和队列可以使用LinkedList模拟
Set:HashSet没有重复记录的集合
Map:HashMap就是哈希表
二叉树可以利用递归的思想来模拟自行设计,从JDK5开始还提供了一个新的队列接口
图!!!没遇到过这样的情况,恐怕还是要自己模拟

㈥ JAVA版和C++版的数据结构有什么不同

数据结构本身是一种逻辑上的概念,它是独立于特定语言或者实现的

比如说链表,概念上说就是一组结点构成的数据结构,其中每个结点均带有后续结点信息。各种语言都可以实现链表,但实现的思路都是基于上面的逻辑概念。

因此,学习数据结构不必拘泥于某种特定语言,归根结底是要把握每个数据结构(逻辑上)的精髓

在这个基础上,每种语言都可以实现特定的数据结构,差别只在于语法实现级别。

另外虽然Java/C++等语言都带有大量的标准类库,但这并不意味着可以忽视数据结构基础理论的学习。这直接关系到实际应用时,是只能死板套用现成模板,还是灵活应用各种结构高效实现需求。

㈦ Java数据结构

使用java集合新出的stream()方法 就是用流的方式处理集合

㈧ Java数据结构与算法有哪些

《Java数据结构和算法》(第2版)介绍了计算机编程中使用的数据结构和算法,对于在计算机应用中如何操作和管理数据以取得最优性能提供了深入浅出的讲解。全书共分为15章,分别讲述了基本概念、数组、简单排序、堆和队列、链表、递归、进阶排序、二叉树、红黑树、哈希表及图形等知识。附录中则提供了运行专题Applet和例程、相关书籍和问题解答。《Java数据结构和算法》(第2版)提供了学完一门编程语言后进一步需要知道的知识。本书所涵盖的内容通常作为大学或学院中计算机系二年级的课程,在学生掌握了编程的基础后才开始本书的学习。

热点内容
php取文本框值 发布:2025-01-25 05:08:50 浏览:245
怎么查看服务器状态 发布:2025-01-25 05:08:42 浏览:715
win7无法访问xp共享打印机 发布:2025-01-25 05:05:04 浏览:805
编程刷分 发布:2025-01-25 04:55:07 浏览:630
世界服务密码是多少 发布:2025-01-25 04:42:52 浏览:48
专车配置有哪些 发布:2025-01-25 04:42:46 浏览:569
java培训班收费 发布:2025-01-25 04:37:53 浏览:766
密码锁如何密码解锁 发布:2025-01-25 04:25:16 浏览:385
ebay如何上传产品 发布:2025-01-25 04:04:37 浏览:823
java判断是否手机访问权限 发布:2025-01-25 04:02:28 浏览:807