線性表的順序結構

2021-07-30 08:50:51 字數 1730 閱讀 4747

實驗一 線性表的基本操作

一、實驗目的

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

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

二、實驗內容

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

三、實驗步驟

1、定義節點

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

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

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

5、按序號查詢乙個元素

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

7、顯示單鏈表所有元素

課本上使用c語言實現的,這裡我用c++實現了一遍,有什麼錯誤請及時指出。下面附上個人渣**

#include 

#include

using

namespace

std;

typedef

int elementtype;

const

int list_init_size = 20;

const

int listincrement = 20;

class sequence

;bool sequence::initlistsq()

this->length = 10;

this->listsize = list_init_size;

return

true;

}bool sequence::listinsert(int i, elementtype e)

if (this->length >= this->listsize)

this->elem = newbase;

this->listsize += listincrement;

}elementtype *q = &(this->elem[i-1]);

for (elementtype *p = &(this->elem[this->length - 1]); p >= q; p--)

*q = e;

this->length++;

return

true;

}bool sequence::listdelete(int i, elementtype &e)

elementtype *p = &(this->elem[i-1]);

e = *p;

elementtype *q = this->elem + this->length - 1;

for (q++; p <= q; p++)

this->length --;

return

true;

}bool sequence::listfindbyindex(int index, elementtype &e)

elementtype *p = this->elem;

while (--index)

e = *(p);

return

true;

}bool sequence::listfindbyvalue(elementtype e, int &i)

index++;

p++;

}i = -1;

return

false;

}void sequence::listprint()

}int main()

線性表 線性表的順序儲存結構

線性表的順序儲存結構 線性結構是乙個資料元素的有序 次序 集。集合中必存在唯一的乙個 第一元素 集合中必存在唯一的乙個 最後元素 除最後元素外,均有唯一的後繼 除第一元素外,均有唯一的前驅。adt list 資料關係 r1 adt list 容易混的概念 引用符號 和引用型操作沒有關係 加工型操作 ...

線性表 線性表的順序儲存結構

include include using namespace std define ok 1 define error 0 define list init size 100 define listincrement 10 typedef int status typedef int elemty...

線性表 線性表的順序儲存結構

include include using namespace std define ok 1 define error 0 define list init size 100 define listincrement 10 typedef int status typedef int elemty...