| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 540 人关注过本帖
标题:求高手用栈实现一个迷宫的问题
只看楼主 加入收藏
格斗小子
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-11-3
收藏
 问题点数:0 回复次数:0 
求高手用栈实现一个迷宫的问题
这是我的栈:
public class SeqStack<E> implements SStack<E> {
    private Object value[];//存储栈的数据元素的数组
    private int top;// 栈顶元素
    public SeqStack(int capacity){//构造指定长度的顺序栈
        this.value=new Object[Math.abs(capacity)];
        this.top=-1;
    }
    public SeqStack(){//够着默认容量的栈
        this(10);
    }
    public boolean isEmpty() {//判断栈空
        return this.top==-1;
        
    }
    public boolean push(E element) {//如栈
        if(element==null){
            return false;
        }
        if(this.top==value.length-1){
            Object temp[]=this.value;
            this.value=new Object[temp.length*2];
            for(int i=0;i<temp.length;i++){
                this.value[i]=temp[i];
            }
        }
        this.top++;
        this.value[this.top]=element;
        return true;
    }
    public E pop() {
        if(!isEmpty()){
            return (E)this.value[this.top--];
        }
        else
            return null;
    }
    public E get() {
        if(!isEmpty()){
            return (E)this.value[this.top];
        }
        else
            return null;
    }
    public String  toString(){
        String str= "(";
        for(int i=0;i<this.value.length;i++){
        str+=this.value[i].toString();
        }
        return str+")";
        
    }
}


package cha3;

public interface SStack<E> {
    boolean isEmpty();
    boolean push(E element);//入栈
    E pop();//出栈
    E get();//取栈顶元素
}
搜索更多相关主题的帖子: 迷宫 
2010-11-03 21:35
快速回复:求高手用栈实现一个迷宫的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014591 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved