//
// ViewController.swift
// learn4
//
// Created by myhaspl on 16/1/23.
// Copyright (c) 2016年 myhaspl. All rights reserved.
//
import Cocoa
class ViewController: NSViewController {
var fifoquene=[Int]()
var lifoquene=[Int]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
@IBOutlet weak var inputnum1: NSTextField!
@IBOutlet weak var inputnum2: NSTextField!
@IBOutlet weak var fifostate: NSTextField!
@IBOutlet weak var lifostate: NSTextField!
@IBAction func lifopop(sender: AnyObject) {
let messagebox:NSAlert=NSAlert()
if lifoquene.count>0{
let mynum=lifoquene.removeLast()
lifostate.stringValue="后进先出"+" "
for num in lifoquene{
lifostate.stringValue=lifostate.stringValue+String(num)+" "
}
messagebox.messageText="您取出了"+String(mynum)
}
else{
messagebox.messageText="队列为空"
}
messagebox.alertStyle=NSAlertStyle.InformationalAlertStyle
messagebox.runModal()
}
@IBAction func lifopush(sender: AnyObject) {
if let mynum=inputnum2.stringValue.toInt(){
lifoquene.append(mynum)
lifostate.stringValue+=" "+String(mynum)
}
}
@IBAction func fifopop(sender: AnyObject) {
let messagebox:NSAlert=NSAlert()
if fifoquene.count>0{
let mynum=fifoquene.removeAtIndex(0)
fifostate.stringValue="先进先出"+" "
for num in fifoquene{
fifostate.stringValue=fifostate.stringValue+String(num)+" "
}
messagebox.messageText="您取出了"+String(mynum)
}
else{
messagebox.messageText="队列为空"
}
messagebox.alertStyle=NSAlertStyle.InformationalAlertStyle
messagebox.runModal()
}
@IBAction func fifopush(sender: AnyObject) {
if let mynum=inputnum1.stringValue.toInt(){
fifoquene.append(mynum)
fifostate.stringValue+=" "+String(mynum)
}
}
}
本博客全部内容是原创,假设转载请注明来源