線性表的鏈式結構

2021-07-30 16:58:06 字數 1328 閱讀 5632

實驗一 線性表的基本操作

一、實驗目的

1)掌握順序表、鍊錶的概念,學會對順序表、鍊錶進行操作。

2)實現順序表、鍊錶的儲存結構,逐步培養解決實際問題的能力

二、實驗內容

順序表、鍊錶結構的生成,插入,刪除,定位,查詢

三、實驗步驟

1、定義節點

2、生成乙個單鏈表(正序建立單鏈表或逆序建立單鏈表)

3、單鏈表中插入乙個元素

4、在單鏈表中刪除乙個元素

5、按序號查詢乙個元素

6、按值(關鍵字)查詢乙個元素

7、顯示單鏈表所有元素

#include

#include

using namespace std;

typedef int elemtype;

class node

;void node::initlist()

void node::creatlist()

p1 = this->head;

elemtype data;

while (cin >>

data

&&data

>

0)

p1->next = p2;

p1 = p2;

p2->next =

null;

}}void node::insertdata(int i, elemtype e)

node->next = head2->next;

head2->next = node;

return;

}void node::printlist()

while (head2->next !=

null)

cout << endl;

}int node::getlength()

return count;

}void node::delele(int i)

now = head2->next;

head2->next = now->next;

free(now);

return;

}elemtype node::findbyindex(int i)

return head2->

data;

}int node::findbyvalue(elemtype e)

index++;

head2 = head2->next;

}index =-1;

return index;

}int main()

線性表的鏈式結構

上一章,我們談到了線性表的順序結構,由於線性表的插入和刪除等操作需要移動元素,造成時間效率低。另外,這種儲存結構需要占用連續的儲存空間。為了彌補順序儲存結構的不足,我們可以討論另一種儲存結構,即鏈式儲存結構,對線性表的插入 刪除不需要移動資料元素,但同時也失去了順序錶可隨機訪問的特點。所謂的鍊錶就是...

線性表的鏈式儲存結構

線性表的鏈式儲存結構 順序儲存結構不足的解決辦法 缺點 最大的缺點就是插入和刪除時需要移動大量元素。為了表示每個資料元素 ai與其直接後續資料元素 ai 1 之間的邏輯關係,對資料元素 ai來說,除了儲存其本身的資訊之外,還需儲存乙個指示其直接後續的資訊。我們把儲存資料元素資訊的域稱為資料域,把儲存...

線性表的鏈式儲存結構

線性表的鏈式儲存結構,雙向鍊錶實現 package 線性表 public class dulinklist public node t data,node prev,node next 儲存該鍊錶的頭節點 private node header 儲存該鍊錶的尾節點 private node tail...