資料結構 2

2021-10-06 00:17:31 字數 1397 閱讀 2978

class

circularqueue

}print()

enqueue

(item)

else

return

(null);

}dequeue()

}

function

linkedlist()

;this

.head=(

)=>head;

this

.size=(

)=>length;

//增加元素

this

.add

=function

(ele)

current.next=node;

}else head=node;

//鍊錶為空

length++

;//新增元素,鍊錶長度增加

}//刪除元素

this

.remove

=function

(ele)

else

pre.next=pre.next.next;

return

("size change from "

+ length--

+" to "

+length);}

}//判斷鍊錶是否為空

this

.isempty=(

)=>

(this

.size()

>0?

false

:true);

//返回元素在鍊錶的索引值

this

.indexof

=function

(ele)

if(current.element===ele) location.

push

(index)

;return location;

}//按照索引值搜尋元素

this

.elementat

=function

(num)

if(num===index)

return

(current.element);}

//按照索引值刪除元素

this

.removeat

=function

(num)}}

//指定索引處新增元素

this

.addat

=function

(num, element)

while

(current.next!=

null)}

}}var s =

newlinkedlist()

;

資料結構 2

2016 02 06 17 38 指標和陣列 指標和一維陣列 陣列名一維陣列名是個指標常量,它存放的是一維陣列第乙個元素的位址,它的值不能被改變 一維陣列名指向的是陣列的第乙個元素 下標和指標的關係 a i a i 假設指標變數的名字為p 則p i的值是p i p所指向的變數所佔的位元組數 指標變數...

資料結構2

定義 只允許在一端插入和刪除的線性表 允許插入和刪除的一端稱為棧頂 top 另一端稱為棧底 bottom 特點後進先出 lifo 棧的棧的主要操作 棧的主要操作主要操作 棧的主要操作 adtstack 棧的陣列表示 順序棧 define stacksize 100typedef char stack...

資料結構 2

class queue object 佇列 雙端佇列 def init self 私有化,封裝 self.queue def enqueue self item 從尾部往佇列中新增乙個元素 def enqueue start self item 從頭部新增元素 雙 self.queue.insert...