[Algorithms] 15. Weave
5635 ワード
質問する



解決策

コミットコード
class Queue {
constructor() {
this.data = [];
}
add(record) {
this.data.unshift(record);
}
remove() {
return this.data.pop();
}
peek() {
return this.data[this.data.length -1]
}
}
function weave(sourceOne, sourceTwo) {
const q = new Queue();
while(sourceOne.peek() || sourceTwo.peek()) {
if (sourceOne.peek()) {
q.add(sourceOne.remove());
}
if(sourceTwo.peek()) {
q.add(sourceTwo.remove());
}
}
return q;
}
Reference
この問題について([Algorithms] 15. Weave), 我々は、より多くの情報をここで見つけました https://velog.io/@peng0code/Algorithms-15.-Weaveテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol