前端之家收集整理的这篇文章主要介绍了
swift手记-4,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//
// 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)
}
}
}
本博客所有内容是原创,如果转载请注明来源