1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      順序表java代碼 java順序棧的實現(xiàn)代碼

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

      java 中的List接口就是順序存儲的集合機構(gòu),底層是用數(shù)組實現(xiàn)的,檢索性能高,插入和刪除性能較低,因為涉及到移位。代碼簡單演示:

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

      ListInteger list = new ArrayListInteger(); // 定義一個用于存放整數(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中的第一個元素100,賦值給a

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

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

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

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

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

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

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

      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)建二叉樹

      public void createBintree() {

      nodeList = new LinkedListNode();

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

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

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

      }

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

      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);

      }

      // 最后一個父節(jié)點

      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 就是線性表.....如果問你具體怎么定義直接超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)建一個順序表,輸出該順序表,將順序表中所有值為x的元素替換成y,再輸出替換后的順序表。

      import java.util.ArrayList;

      import java.util.List;

      public class Test

      {

      /**

      * @param args

      */

      public static void main(String[] args)

      {

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

      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("序號:" + 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("序號:" + i + ", 值:" + a.get(i));

      }

      }

      }


      本文名稱:順序表java代碼 java順序棧的實現(xiàn)代碼
      鏈接地址:http://ef60e0e.cn/article/doedchg.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        中江县| 胶南市| 清河县| 广西| 宜兰县| 卓资县| 肥乡县| 盖州市| 三台县| 萨嘎县| 精河县| 宾阳县| 衡水市| 黄山市| 金昌市| 石屏县| 同心县| 周宁县| 观塘区| 义乌市| 广东省| 马山县| 岳阳县| 郴州市| 利川市| 柏乡县| 绥江县| 上饶市| 湘潭县| 绩溪县| 囊谦县| 无锡市| 新干县| 商洛市| 休宁县| 宜春市| 三都| 太康县| 武强县| 大洼县| 通辽市|