// // ViewController.swift // learn3 // // Created by myhaspl on 16/1/23. // Copyright (c) 2016年 myhaspl. All rights reserved. // import Cocoa class ViewController: NSViewController { var mystatck:[Int32]=[] 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 inputnum: NSTextField! @IBOutlet weak var stackstate: NSTextField! @IBAction func pushNumber(sender: AnyObject) { mystatck.append(inputnum.intValue) stackstate.stringValue="堆栈情况" for mynum in mystatck{ stackstate.stringValue+=String(mynum)+" " } } @IBAction func popNumber(sender: AnyObject) { let messageBox:NSAlert=NSAlert() if mystatck.count>0{ let removed = mystatck.removeLast() stackstate.stringValue="堆栈情况" for mynum in mystatck{ stackstate.stringValue+=String(mynum)+" " } messageBox.messageText="您取出了"+String(removed) } else{ messageBox.messageText="堆栈为空" } messageBox.alertStyle=NSAlertStyle.InformationalAlertStyle messageBox.runModal() } }
堆栈算法
本博客所有内容是原创,如果转载请注明来源
http://blog.csdn.net/myhaspl/
}