# 白板題 ```js //TODO stack->push pop 實作一個queue //stack先進後出 queue先進先出 var stack; var stack_top; var temp_stack; dequeue(top) // queue拿一個東西出來 { if(top!=0) { temp_stack.push(stack.pop()); dequeue(top-1); } else { //先把最先進資料存下。 var result = stack.pop(); // stack就空了 // 把temp內資料放回stack for(var temp_count = 0; temp_count<temp_stack.length; temp_count++) { stack.push(temp_stack.pop()); } // 回傳stack最先進資料 return result; } } enqueue(element) // 放一個東西到queue裡面 { stack.push(element); } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up