diff --git a/codes/typescript/chapter_stack_and_queue/queue.ts b/codes/typescript/chapter_stack_and_queue/queue.ts index eb7b8135..0701a9af 100644 --- a/codes/typescript/chapter_stack_and_queue/queue.ts +++ b/codes/typescript/chapter_stack_and_queue/queue.ts @@ -5,8 +5,8 @@ */ /* 初始化队列 */ -// Typescript 没有内置的队列,可以把 Array 当作队列来使用 -// 注意:虽然Typescript有shift()函数可以去除队首元素,但是时间复杂度是O(n)的。 +// TypeScript 没有内置的队列,可以把 Array 当作队列来使用 +// 注意:由于是数组,所以 shift() 的时间复杂度是 O(n) const queue: number[] = []; /* 元素入队 */ @@ -20,6 +20,7 @@ queue.push(4); const peek = queue[0]; /* 元素出队 */ +// O(n) const poll = queue.shift(); /* 获取队列的长度 */ @@ -28,4 +29,4 @@ const size = queue.length; /* 判断队列是否为空 */ const empty = queue.length === 0; -export { }; \ No newline at end of file +export { };