前言與鍊錶實現陣列

2021-09-17 02:19:03 字數 1236 閱讀 2746

最近工作上需要依照現有資料生成巢狀json物件形式的組織機構列表,一時覺得無從下手,請教同事大神才知道此乃資料結構相關知識,遂惡補相關基礎並在此記錄。

資料結構可以分為:1、列表;2、線性;3、樹形;4、圖 四種基本結構。何為資料結構?我理解就是資料的結構。。。即承載資料的形式。資料結構中的線性結構有陣列和鍊錶,本文即對鍊錶進行簡單總結,在後續文章中會實現幾種基本的資料結構。

1 鍊錶是什麼
鍊錶相關概念

2 用鍊錶實現陣列和其基本操作,以下附上**
function array()

e=new element(e);

if(index==-1)else

return head;

} //刪除最後乙個元素

this.deletelast=function()

}return head;

} //按序號取元素

this.get=function(inx)

}} //按位置插入元素

this.insert=function(inx,e)

e=new element(e);

if(inx==0)else

return head;

} //刪除特定位置元素

this.deleteelement=function(inx)else

return head;

}}

同時提供兩種遍歷鍊錶的方法

//遍歷鍊錶(遞迴)

function loop(head)

return loop(head.next);

}

//遍歷鍊錶(非遞迴)

function looplinkedlist(head)

}

具體使用方法

var obj = new array();

console.time('addtest');

obj.add('aaa');

obj.add('bbb');

obj.add('ccc');

obj.add('ddd');

var head=obj.add('eee');

console.log(head);

console.timeend('addtest');

棧 陣列與鍊錶實現

棧的實現一般由陣列與鍊錶實現,但陣列實現較為常見,鍊錶實現一般不常用。以下給出兩種實現方式的完整 一 陣列實現 注意要點 1.棧為空時 top 1 2.棧滿時 top capacity 如下 adt stack 儲存結構 陣列 struct stackrecord typedef stackreco...

陣列實現鍊錶

測試類 public class listtest 再新增元素 list.add 100 list.modify 10,100 取出元素 for int i 0 i list.size i 建立乙個陣列佇列 author 閉耀堯 public class mylist 將心陣列的值賦給初始陣列的最後...

棧的鍊錶實現 與 陣列實現

鍊錶實現 include include define false 0 define true 1 define ok 1 define error 1 typedef char datatype struct stacknode stacks void initstack stacks s int...