首页 > 代码库 > Demo6
Demo6
public class Main { public static void main(String args[]) { Stack a = new Stack(); System.out.println(a.isEmpty()); System.out.println(a.getTop()); a.push(new String ("3")); System.out.println(a.getTop()); a.push(new String ("1")); a.push(new String ("9")); System.out.println(a.pop()); a.push(new String ("5")); a.push(new String ("6")); System.out.println(a.getTop()); System.out.println(a.isEmpty()); a.trans(32); } }
import java.util.Scanner; public class Stack { private Object[] stack; private int length ; public Stack(){ stack = new Object[100]; } public boolean isEmpty() { if(length==0) return true; else return false; } public int len() { return length; } public void push(Object elem) { stack[length++] = elem; } public Object pop() { return stack[--length]; } public Object getTop() { if(length == 0) return -1; else { int len = length-1; return stack[len]; } } public void trans(int n) { //Scanner scan = new Scanner(System.in); //while(scan.hasNext()) //{ //int n = scan.nextInt(); Stack a = new Stack(); while(n != 0) { a.push(n % 2); n = n / 2; } while(a.isEmpty() == false) { System.out.print(a.pop()); } System.out.println(); //} } }
Demo6
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。