我制作了一个Stack和一个ArrayList来进行研究.实际上我现在想要将我的Stack替换为ArrayList,但是如何将Stack转换为ArrayList?推,弹......怎么样?
谢谢
public static ArrayList<State> search(State finalstate)
{
ArrayList<State> toreturn = new ArrayList<State>();
Stack<State>mystack=new Stack<State>();
mystack.push(initState);
State currState;
currState=initState;
while(!mystack.isEmpty() && !currState.equals(finalstate) )
{
currState=mystack.pop();
toreturn.add(currState);
if(currState.vecinos.containsKey("up"))
{
mystack.push(currState).vecinos.get("up");
}
if(currState.vecinos.containsKey("down"))
{
mystack.push(currState).vecinos.get("down");
}
if(currState.vecinos.containsKey("left"))
{
mystack.push(currState).vecinos.get("left");
}
if(currState.vecinos.containsKey("right"))
{
mystack.push(currState).vecinos.get("right");
}
}
return toreturn;
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有一些选项的按钮.
- (IBAction)monstrarActionSheet:(id)sender {
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Titulo"
delegate:self
cancelButtonTitle:@"Mejor no" destructiveButtonTitle:@"Que miedo" otherButtonTitles:@"Otro boton 1", @"Otro boton 2", nil];
[action showInView: self.view];
Run Code Online (Sandbox Code Playgroud)
选择某个选项后,我会在日志中显示一条消息,以显示选择了哪个按钮.
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
/*if(actionSheet.tag == 1){
}*/
NSLog(@"El usuario seleciono el boton %ld", (long)buttonIndex);
}
Run Code Online (Sandbox Code Playgroud)
在我的ViewController.h我的按钮和标签是这样定义的
@interface ViewController : UIViewController <UIActionSheetDelegate>
@property (weak, nonatomic) IBOutlet UILabel *lbViewController1;
Run Code Online (Sandbox Code Playgroud)
如何将所选UIActionSheet按钮的标题放入我的lbViewController1标签中?