欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

順序表java代碼 java順序棧的實(shí)現(xiàn)代碼

如何用JAVA語(yǔ)言建立含有若干個(gè)元素的順序表,并實(shí)現(xiàn)插入,刪除,查找等基本操作

java 中的List接口就是順序存儲(chǔ)的集合機(jī)構(gòu),底層是用數(shù)組實(shí)現(xiàn)的,檢索性能高,插入和刪除性能較低,因?yàn)樯婕暗揭莆弧4a簡(jiǎn)單演示:

成都地區(qū)優(yōu)秀IDC服務(wù)器托管提供商(創(chuàng)新互聯(lián)公司).為客戶提供專業(yè)的成都服務(wù)器托管,四川各地服務(wù)器托管,成都服務(wù)器托管、多線服務(wù)器托管.托管咨詢專線:028-86922220

ListInteger list = new ArrayListInteger(); // 定義一個(gè)用于存放整數(shù)的集合list,

list.add(100);

list.add(200);

list.add(300); // 將100,200,300 一次加入到list中

System.out.println(list.toString()); // 查看結(jié)果

int a = list.get(0) ; // 這將找出list中的第一個(gè)元素100,賦值給a

System.out.println(a); // 100

list.remove(2); // 刪除list中的第三個(gè)元素

System.out.println(list.toString()); // 查看結(jié)果

------------------------------------------------------------------------------------------------------

比較粗略,詳細(xì)內(nèi)容請(qǐng)查看ArrayList 的 API 。祝你學(xué)習(xí)進(jìn)步。

java二叉樹(shù)的順序表實(shí)現(xiàn)

做了很多年的程序員,覺(jué)得什么樹(shù)的設(shè)計(jì)并不是非常實(shí)用。二叉樹(shù)有順序存儲(chǔ),當(dāng)一個(gè)insert大量同時(shí)順序自增插入的時(shí)候,樹(shù)就會(huì)失去平衡。樹(shù)的一方為了不讓塌陷,會(huì)增大樹(shù)的高度。性能會(huì)非常不好。以上是題外話。分析需求在寫(xiě)代碼。

import java.util.List;

import java.util.LinkedList;

public class Bintrees {

private int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9};

private static ListNode nodeList = null;

private static class Node {

Node leftChild;

Node rightChild;

int data;

Node(int newData) {

leftChild = null;

rightChild = null;

data = newData;

}

}

// 創(chuàng)建二叉樹(shù)

public void createBintree() {

nodeList = new LinkedListNode();

// 將數(shù)組的值轉(zhuǎn)換為node

for (int nodeIndex = 0; nodeIndex array.length; nodeIndex++) {

nodeList.add(new Node(array[nodeIndex]));

}

// 對(duì)除最后一個(gè)父節(jié)點(diǎn)按照父節(jié)點(diǎn)和孩子節(jié)點(diǎn)的數(shù)字關(guān)系建立二叉樹(shù)

for (int parentIndex = 0; parentIndex array.length / 2 - 1; parentIndex++) {

nodeList.get(parentIndex).leftChild = nodeList.get(parentIndex * 2 + 1);

nodeList.get(parentIndex).rightChild = nodeList.get(parentIndex * 2 + 2);

}

// 最后一個(gè)父節(jié)點(diǎn)

int lastParentIndex = array.length / 2 - 1;

// 左孩子

nodeList.get(lastParentIndex).leftChild = nodeList.get(lastParentIndex * 2 + 1);

// 如果為奇數(shù),建立右孩子

if (array.length % 2 == 1) {

nodeList.get(lastParentIndex).rightChild = nodeList.get(lastParentIndex * 2 + 2);

}

}

// 前序遍歷

public static void preOrderTraverse(Node node) {

if (node == null) {

return;

}

System.out.print(node.data + " ");

preOrderTraverse(node.leftChild);

preOrderTraverse(node.rightChild);

}

// 中序遍歷

public static void inOrderTraverse(Node node) {

if (node == null) {

return;

}

inOrderTraverse(node.leftChild);

System.out.print(node.data + " ");

inOrderTraverse(node.rightChild);

}

// 后序遍歷

public static void postOrderTraverse(Node node) {

if (node == null) {

return;

}

postOrderTraverse(node.leftChild);

postOrderTraverse(node.rightChild);

System.out.print(node.data + " ");

}

public static void main(String[] args) {

Bintrees binTree = new Bintrees();

binTree.createBintree();

Node root = nodeList.get(0);

System.out.println("前序遍歷:");

preOrderTraverse(root);

System.out.println();

System.out.println("中序遍歷:");

inOrderTraverse(root);

System.out.println();

System.out.println("后序遍歷:");

postOrderTraverse(root);

}

}

用java順序表完成以下程序

ArrayListInteger la = new ArrayListInteger();

ArrayListInteger lb = new ArrayListInteger();

//ArrayList 就是線性表.....如果問(wèn)你具體怎么定義直接超ArrayList的源代碼給他

la.add(3);

la.add(5);

la.add(8);

la.add(11);

lb.add(2);

lb.add(6);

lb.add(8);

lb.add(9);

lb.add(11);

lb.add(15);

lb.add(20);

SetInteger set = new HashSetInteger();

set.addAll(la);

set.addAll(lb);

for (Integer integer : set) {

System.out.print(integer+" ");

}

System.out.println("");

la.addAll(lb);

Collections.sort(la);

for (Integer integer : la) {

System.out.print(integer+" ");

Java程序:創(chuàng)建一個(gè)順序表,輸出該順序表,將順序表中所有值為x的元素替換成y,再輸出替換后的順序表。

import java.util.ArrayList;

import java.util.List;

public class Test

{

/**

* @param args

*/

public static void main(String[] args)

{

// 創(chuàng)建一個(gè)順序表

ListString a = new ArrayListString();

a.add("a");

a.add("b");

a.add("c");

a.add("x");

a.add("d");

a.add("x");

// 按順序輸出創(chuàng)建的順序表

for (int i = 0; i a.size(); i++)

{

System.out.println("序號(hào):" + i + ", 值:" + a.get(i));

}

// 循環(huán)替換x為y

for (int i = 0; i a.size(); i++)

{

String value = a.get(i);

if ("x".equals(value))

{

a.set(i, "y");

}

}

// 按順序輸出替換后的順序表

for (int i = 0; i a.size(); i++)

{

System.out.println("序號(hào):" + i + ", 值:" + a.get(i));

}

}

}

標(biāo)題名稱:順序表java代碼 java順序棧的實(shí)現(xiàn)代碼
標(biāo)題URL:http://chinadenli.net/article46/doedchg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT定制開(kāi)發(fā)網(wǎng)站設(shè)計(jì)公司外貿(mào)網(wǎng)站建設(shè)網(wǎng)站收錄全網(wǎng)營(yíng)銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司