我阅读了关于Deque的文档,它只是说peek方法将返回此Deque所代表的队列的头部。但它如何知道我的结构是队列还是堆栈。
class LSPlayerViewController : AVPlayerViewController {
private var btnPlay : UIButton!
func addControls() {
self.showsPlaybackControls = false
//PLAY BUTTON
let btnPlayRect = CGRect(x: 0, y: 0, width: 19, height: 25)
btnPlay = UIButton(frame: btnPlayRect)
btnPlay.center = self.view.center
btnPlay.setImage(#imageLiteral(resourceName: "PauseIcon"), for: .normal)
btnPlay.addTarget(self, action: #selector(self.playButtonTapped(sender:)), for: .touchUpInside)
btnPlay.alpha = 0
btnPlay.isUserInteractionEnabled = true
self.view.addSubview(btnPlay)
}
func playButtonTapped(sender: UIButton!) {
if sender.isPlayIconOn == true {
sender.setImage(#imageLiteral(resourceName: "PauseIcon"), for: .normal)
self.player?.play()
} else {
sender.setImage(#imageLiteral(resourceName: "PlayIcon"), for: .normal)
self.player?.pause()
}
}
答案 0 :(得分:1)
它不知道是队列还是堆栈,因为您已经提到peek只会返回Deque的头部。这里的要点是什么是push&offer(也就是pull&poll)的头值,以防push head指向新推送的元素,但在offer head中仍然指向第一个插入的元素。因此,peek只返回head值,并且通过调用的队列/堆栈方法来更新head值。
在此处https://www.baeldung.com/java-array-deque,为更清楚起见,结帐点4.1和4.2。