数据结构中的基本结构分析

Terwer Java SE评论139字数 1517阅读5分3秒阅读模式

数据结构

  • 一般将数据结构分为两大类:线性结构 和 非线性结构 。

    线性数据结构有 线性表、栈、队列、串、数组和文件;非线性数据结构有 树和图。文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

线性表

  • 数据结构中的基本结构分析文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    * 线性表的数据结构是 n 个数据元素的有限序列:
    
    $\left( {{{\rm{a}}_1},{a_2} \cdots {a_n}} \right)$
    * n 为线性表的长度($n \ge 0$), `n=0` 的表称为空表。
    
  • 数据元素呈线性关系。必存在唯一的一个称为 “第一个” 的数据元素;必须在唯一的一个称为 “最后一个” 的元素;除第一个元素外,每个元素都有唯一的一个先驱元素,除最后一个元素外,每个元素都有且只有一个后继元素。文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html
  • 所有数据元素在同一个线性表中必须是相同的数据类型。
  • 线性表按照其存储结构可以分为 顺序表 和 链表 。文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    用顺序存储结构存储的线性表称为​ 顺序表 。文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    用链式存储结构存储的线性表称为 链表 。文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

  • 将线性表中的数据元素依次存储在某个区域中,所形成的表称为 顺序表 。一维数组就是用顺序方式存储的线性表。

链表

  • 单向链表文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    数据结构中的基本结构分析文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    插入文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    数据结构中的基本结构分析文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    删除文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    数据结构中的基本结构分析文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    单链表使用案例:文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    // 需求:定义一个 Node 节点,包含 node1、node2、node3 ;然后在 node1和 node2 之间插入 node4 ,最后删除 node4 。
    
    // Node.java
    public class Node {
      /**
       * 存放节点数据本身
       */
      String data;
    
      /**
       * 存放指向下一个节点的引用
       */
      Node next;
    
      @Override
      public String toString() {
          return "Node{" +
                  "data='" + data + '\'' +
                  ", next=" + next +
                  '}';
      }
    }
    
    // NodeTest.java
    public class NodeTest {
      public static void main(String[] args) {
          Node node1 = new Node();
          node1.data = "node1";
          Node node2 = new Node();
          node2.data = "node2";
          Node node3 = new Node();
          node3.data = "node3";
    
          node1.next = node2;
          node2.next = node3;
    
          System.out.println("node1=>" + node1);
          System.out.println("node2=>" + node2);
          System.out.println("node3=>" + node3);
          System.out.println("----------------------");
    
          System.out.println(node1.next.next.data);
          System.out.println("----------------------");
    
          // 在node1和node2之间插入node4
          Node node4 = new Node();
          node4.data = "node4";
          node4.next = node2;
          node1.next = node4;
    
          System.out.println(node1.next.next.next.data);
          System.out.println("----------------------");
    
          // 删除node4
          node1.next = node4.next;
          node4 = null;
    
          System.out.println(node1.next.next.data);
      }
    }
    
  • 循环链表

    数据结构中的基本结构分析文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

  • 双向循环链表文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

    数据结构中的基本结构分析文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html

  • 栈(Stack)也是一种特殊的线性表,是一种后进先出(LIFO)的结构。
  • 栈是限定仅在表尾进行插入和删除运算的线性表,表尾成为栈顶(top),表头成为栈底(bottom)。
  • 栈的物理存储可以用顺序存储结构,也可以用链式存储结构。
文章源自浅海拾贝-https://blog.terwergreen.com/basic-structural-analysis-in-data-structure-171wfj.html
相关文章
  • 扫码加我微信
  • 验证消息请输入:来自你的博客
  • weinxin
  • 我的微信公众号
  • 微信扫一扫与我交流吧
  • weinxin
Terwer
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: