Skip to main content
Latest
File
// deno-lint-ignore no-explicit-anyexport default interface CQueue<T = any> { appendTail: (value: T) => void; deleteHead: () => T | number;}
// deno-lint-ignore no-explicit-anyexport default function CQueue<T = any>(): CQueue<T> { const inStack: Array<T> = []; const outStack: Array<T> = []; function deleteHead(): T | number { if (!outStack.length) { if (!inStack.length) { return -1; } in2out(); } return outStack.pop() as T; } function appendTail(value: T): void { inStack.push(value); } function in2out() { while (inStack.length) { outStack.push(inStack.pop() as T); } } return { appendTail, deleteHead };}