JS) stack,Queue
6538 ワード
1. stack
2. Queue
1. stack
!)Webブラウザアクセス履歴
!!)元に戻す(ctrl+Z)
!!!)逆シーケンス文字列の作成
//스택을 만드는 클래스
class Makestack {
constructor() {
this.storage = {};
this.top = 0; //스택을 분별하기 위한 키값
}
push(element) {
this.storage[this.top] = element;
this.top++; //스택이 추가되면 카운트가 하나씩 없어짐
}
pop() {
if (Object.keys(this.storage).length === 0) {
return 'none stack'
}
const result = this.storage[Object.keys(this.storage).length-1];
delete this.storage[Object.keys(this.storage).length-1];
this.top--;//스택이 삭제되면 카운트도 -1되어 다음 스택의 카운트에 영향을 주지 않아야함
return result;
}
}
2. Queue
!)
EX)
//큐을 만드는 클래스
class MakeQueue {
constructor(){
this.storage =[]
}
inputdata(element){
this.storage.push(element)//맨끝에 데이터가 추가된다.
}
outputdata(){
this.storage.shift//가장 앞의 데이터가 빠져나간다.
}
}
Reference
この問題について(JS) stack,Queue), 我々は、より多くの情報をここで見つけました https://velog.io/@baek1008/자료구조-stackQueueGraphTreeテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol