国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - 淺談線性表的原理及簡單實現方法

淺談線性表的原理及簡單實現方法

2020-11-19 10:33Java教程網 Java教程

下面小編就為大家帶來一篇淺談線性表的原理及簡單實現方法。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

一、線性表

原理:零個或多個同類數據元素的有限序列

原理圖:

淺談線性表的原理及簡單實現方法

特點 :

1、有序性

2、有限性

3、同類型元素

4、第一個元素無前驅,最后一個元素無后繼,中間的元素有一個前驅并且有一個后繼

線性表是一種邏輯上的數據結構,在物理上一般有兩種實現 順序實現和鏈表實現

二、基于數組的 線性表順序實現

原理 : 用一段地址連續的存儲單元依次存儲線性表數據元素。

原理圖:

淺談線性表的原理及簡單實現方法

算法原理:

1、初始化一個定長的數組空間 elementData[] , size 存儲長度 存儲元素

2、通過索引來快速存取元素

3、通過數組復制實現元素的插入和刪除

總結:

1、無需為表示表中元素之間的邏輯關系增加額外的存儲空間

2、可以快速存取表中任一位置元素

3、插入和刪除需要進行數組復制(即大量元素的移動)

4、線性表長度變化較大時,需要頻繁擴容,并造成存儲空間碎片

實現代碼:

接口定義:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package online.jfree.base;
 
/**
 * author : Guo LiXiao
 * date : 2017-6-14 11:46
 */
 
public interface LineList <E>{
 
 /**
  * lineList 是否為空
  * @return
  */
 boolean isEmpty();
 
 /**
  * 清空 lineList
  */
 void clear();
 
 /**
  * 獲取指定位置元素
  * @param index
  * @return
  */
 E get(int index);
 
 /**
  * 獲取元素第一次出現的位置
  * @param e
  * @return
  */
 int indexOf(E e);
 
 /**
  * 判斷 lineList是否包含指定元素
  * @param e
  * @return
  */
 boolean contains(E e);
 
 /**
  * 設置指定位置數據,如數據已存在 則覆蓋原數據
  * @param index
  * @param e
  * @return
  */
 E set(int index, E e);
 
 /**
  * 移除指定位置元素
  * @param index
  * @return
  */
 E remove(int index);
 
 /**
  * 在lineList結尾插入元素
  * @param e
  * @return
  */
 E add(E e);
 
 /**
  * 在index后面插入元素
  * @param index
  * @param e
  * @return
  */
 E add(int index, E e);
 
 /**
  * 返回lineList長度
  * @return
  */
 int size();
 
 
 
}

算法實現:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package online.jfree.base;
 
/**
 * author : Guo LiXiao
 * date : 2017-6-15 13:44
 */
 
public class OrderedLineList<E> implements LineList<E> {
 
 private static final int INIT_CAPACITY = 10;
 
 private transient E[] elementData;
 
 private transient int elementLength;
 
 private int size;
 
 public OrderedLineList() {
  this(0);
 }
 
 public OrderedLineList(int initCapacity) {
  init(initCapacity);
 }
 
 private void init(int initCapacity) {
  if (initCapacity >= 0) {
   this.elementData = (E[]) new Object[initCapacity];
   this.elementLength = initCapacity;
  } else {
   throw new IllegalArgumentException("Illegal Capacity: " +
     initCapacity);
  }
  this.size = 0;
 }
 
 /**
  * 擴容
  */
 private void dilatation() {
  int oldCapacity = this.elementLength;
  int newCapacity = oldCapacity;
  if (oldCapacity <= this.size) {
   newCapacity = oldCapacity + INIT_CAPACITY;
  }else if(oldCapacity - INIT_CAPACITY > this.size){
   newCapacity = oldCapacity - INIT_CAPACITY;
  }
  if (oldCapacity != newCapacity){
   E[] newElementData = (E[]) new Object[newCapacity];
   System.arraycopy(elementData, 0, newElementData, 0, oldCapacity);
   this.elementLength = newCapacity;
   this.elementData = newElementData;
  }
 }
 
 /**
  * 校驗列表索引越界
  * @param index
  */
 private void checkCapacity(int index){
  if (index > this.size - 1 || index < 0)
   throw new IndexOutOfBoundsException(new StringBuffer("[index : ").append(index).append("] , [size : ").append(size).append("] ").toString());
 }
 
 @Override
 public boolean isEmpty() {
  return this.size == 0;
 }
 
 @Override
 public void clear() {
  this.init(0);
 }
 
 @Override
 public E get(int index) {
  this.checkCapacity(index);
  return this.elementData[index];
 }
 
 @Override
 public int indexOf(E e) {
  for (int i = 0; i < this.size; i++){
   if (e == null && elementData[i] == null || e.equals(elementData[i])){
    return i;
   }
  }
  return -1;
 }
 
 @Override
 public boolean contains(E e) {
  return this.indexOf(e) > 0;
 }
 
 @Override
 public E set(int index, E e) {
  this.checkCapacity(index);
  this.dilatation();
  E oldElement = this.elementData[index];
  this.elementData[index] = e;
  return oldElement;
 }
 
 @Override
 public E remove(int index) {
  this.dilatation();
  E e = elementData[index];
  if (index == size - 1) elementData[index] = null;
  else {
   int length = size - index - 1;
   System.arraycopy(elementData, index + 1, elementData, index, length);
  }
  size --;
  return e;
 }
 
 @Override
 public E add(E e) {
  return this.add(size, e);
 }
 
 @Override
 public E add(int index, E e) {
  this.dilatation();
  if (index == size) elementData[index] = e;
  else {
   index++;
   int lastLength = size - index;
   E[] lastElementData = (E[]) new Object[lastLength];
   System.arraycopy(elementData, index, lastElementData, 0, lastLength);
   elementData[index] = e;
   System.arraycopy(lastElementData, 0, elementData, index + 1, lastLength);
  }
  size ++ ;
  return e;
 }
 
 @Override
 public int size() {
  return this.size;
 }
 
}

以上這篇淺談線性表的原理及簡單實現方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 国产欧美精品一区二区三区 | 久久久久久国产精品高清 | 欧美黄色一级 | 久久丁香 | 精品免费久久久久久久苍 | 国产一区二区精品在线观看 | 最新中文字幕在线 | 人人爽人人爽人人片av | 国产传媒自拍 | 日韩精品在线视频 | 99热激情| 26uuu成人免费毛片 | 国产中文字幕在线 | 日韩一区免费在线观看 | 国产成人精品一区二区三区四区 | 狠狠干狠狠干 | 在线免费黄 | 国产视频久久 | 国产精品日韩一区二区 | 欧美福利网 | 成人午夜精品一区二区三区 | 黄色一级片免费播放 | 精品久久精品久久 | 国产aaaaav久久久一区二区 | 国产三级一区 | 亚洲视频二区 | 亚洲精品国产综合区久久久久久久 | 午夜电影av| 国产精品久久久久久久久久免费动 | 极品videossex中国妞hd | 99久久99| 欧美综合一区 | 日日夜夜摸 | 一区二区三区高清 | 欧美一区二区三区免费 | 激情久久av一区av二区av三区 | 久久精品国产一区二区三区不卡 | 精品国产久 | 九九综合久久 | 嫩草精品 | 亚洲成年人网站在线观看 |