//http://blog.csdn.net/myhaspl/class VIEwController: NSVIEwController { private let trIEroot:TrIENode = TrIENode (str: " ",nstate: NoteState.Root)//http://blog.csdn.net/myhaspl/ overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw. }//http://blog.csdn.net/myhaspl/ overrIDe var representedobject: AnyObject? { dIDSet { // Update the vIEw,if already loaded. } } //http://blog.csdn.net/myhaspl/ private func createTrIENode(current:TrIENode,mystr:String)->TrIENode { let mynode:TrIENode=TrIENode(str: mystr,nstate: NoteState.NoneTerminal) current.link[mystr]=mynode return mynode } //http://blog.csdn.net/myhaspl/ private func trIEinput(current:TrIENode,str:String,isfind:Bool)->TrIENode? { if let nextstate=current.link[str]{ return nextstate } else if isfind{ return nil } else{ return createTrIENode(current,mystr:str) } } private func readstr(word:String){ var currnode:TrIENode=trIEroot var inputstr:String="" for mychar in word { inputstr.append(mychar) currnode = trIEinput(currnode,str: inputstr,isfind: false)! } currnode.state=NoteState.Terminal }//http://blog.csdn.net/myhaspl/ private func findstr(word:String)->Bool{ var mynode:TrIENode=trIEroot var inputstr:String="" for mychar in word { inputstr.append(mychar) if let nextnode = trIEinput(mynode,isfind: true) { mynode=nextnode } else{ return false } } if mynode.state==NoteState.Terminal{ return true } else{ return false } }//http://blog.csdn.net/myhaspl/ @IBOutlet weak var mywords: NSTextFIEld! @IBOutlet weak var inputtxt: NSTextFIEld! @IBAction func finDWord(sender: AnyObject) { let finDW:Bool=findstr(inputtxt.stringValue) let messageBox:NSAlert=NSAlert() if finDW==true{ messageBox.messageText="找到"+inputtxt.stringValue } else{ messageBox.messageText="没找到"+inputtxt.stringValue } messageBox.alertStyle=NSAlertStyle.informationalAlertStyle messageBox.runModal() } @IBAction func createword(sender: AnyObject) { readstr(inputtxt.stringValue) mywords.stringValue+=inputtxt.stringValue mywords.stringValue+=" " } }
本博客所有内容是原创,如果转载请注明来源 http://blog.csdn.net/myhaspl/
以上是内存溢出为你收集整理的swift算法手记-9全部内容,希望文章能够帮你解决swift算法手记-9所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)