1.掌qu
1.单列表实现栈
class Node{
//https://blog.csdn.net/wuzhaojun1st/article/details/78010693
Object element;
Node next;
public Node(Object element) {
this(element,null);
}
public Node(Object element, Node next) {
this.element = element;
this.next = next;
}
public Object getElement() {
return element;
}
}
class ListStack{
Node header;//栈顶元素
int elementCount;//栈内元素个数
int size;//栈的大小
public ListStack() {
header=null;
elementCount=0;
size=0;
}
public ListStack(int size) {
header=null;
elementCount=0;
this.size=size;
}
public void setHeader(Node header) {
this.header = header;
}
public boolean isFull(){
if (elementCount==size){
return true;
}
return false;
}
public boolean isEmpty(){
if (elementCount==0){
return true;
}
return false;
}
public void push(Object value){
if (this.isFull()){
throw new RuntimeException("Stack is full");
}
header=new Node(value,header);
elementCount++;
}
public Object pop(){
if (this.isEmpty()){
throw new RuntimeException("stack is empty");
}
Object object=header.getElement();
header=header.next;
elementCount--;
return object;
}
public Object peak(){
if (this.isEmpty()){
throw new RuntimeException("stack is empty");
}
return header.getElement();
}
}
2.实现一个简单计算器
3.A的攻击范围,问是否打到B
2、58
1.凑零钱
2.合并且排序
3.问你路径为0 1 ,能到达不
3、 4399
1.判断ip地址
public static boolean validate(String address) {
//最开始要判断address是否为空的情况,增加代码的健壮性
if(address.length()==0||address.equals(" ")
||address==null) {
return false;
}
//1.将ipv4地址进行分割
String[] addressarray=address.split("\\.");
//2.判断ipv4地址是否是四位
if(addressarray.length!=4) return false;
//3.判断ipv4地址的取值范围,和前导为零的问题
for (int j = 0; j < addressarray.length; j++) {
Integer address_valueof;
//此异常捕获字段,是用来判断是否是a.1.23.4这种情况,直接返回false,防止出现异常抛出
try {
address_valueof=Integer.valueOf(addressarray[j]);
}catch(NumberFormatException e) {
return false;
}
//addressarray[j].equals(address_valueof.toString()消除00的情况
if(address_valueof>-1&&address_valueof<256
&&addressarray[j].equals(String.valueOf(address_valueof))) {
continue;
}else {
return false;
}
}
return true;
}