蓝桥-算法-栈

    xiaoxiao2021-03-26  6

    package com.jkxy.queue; import java.util.Stack; public class StackPack { public static void main(String[] args) { int i,mid,next; Stack s=new Stack(); Object[] c={'a','d','f','d','a'}; mid=c.length/2-1;//第二个数,标号爲一 for(i=0;i<=mid;i++){ s.push(c[i]); } if(c.length%2==0){ next=mid+1; }else{ next=mid+2; } for(i=next;i<=c.length-1;i++){ if(c[i]!=s.pop()){ break; } } if(s.empty()){ System.out.println("yes"); }else{ System.out.println("no"); } } }

    /用Stack判断回文,实例化Stack对象s,待检测字符数组。待检测字符数组左侧入栈,入栈左侧与右侧逐一比较,为回文则栈空,否则栈非空。/

    转载请注明原文地址: https://ju.6miu.com/read-650292.html

    最新回复(0)