public class Stack {
private int array[];
private int max;
private int top;
public Stack(int max){
this.max = max;
array = new int[max];
top = 0;
}
public void push(int value){
if(isFull()){
System.out.println("full,can not insert");
return;
}
array[top++]=value;
}
public int pop(){
return array[--top];
}
public boolean isEmpty(){
if(top == 0){
return true;
}
return false;
}
public boolean isFull(){
if(top == max ){
return true;
}
return false;
}
public void display(){
while(!isEmpty()){
System.out.println(pop());
}
}
public static void main(String[] args) {
Stack s = new Stack(5);
s.push(1);
s.push(3);
s.push(5);
s.push(5);
s.push(5);
s.display();
}
}
public String reverse(String in){
String out="";
for (int i = 0; i < in.length(); i++) {
char c = in.charAt(i);
push(c);
}
while(!isEmpty()){
out+=pop();
}
return out;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String string = s.nextLine();
Stack st = new Stack(string.length());
System.out.println(st.reverse(string));
}
public static void main(String[] args) {
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader b = new BufferedReader(is);
String string="";
try {
string = b.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Stack st = new Stack(string.length());
System.out.println(st.reverse(string));
}
public int charat(char c){
for (int i = 0; i < array.length; i++) {
if(c == array[i])
return i;
}
return array.length;
}
public void match(String in){
String out="";
for (int i = 0; i < in.length(); i++) {
char c = in.charAt(i);
if(c == '{' || c == '(' || c == '[' ){
push(c);
}
if(c == '}' || c == ')' || c == ']'){
char temp = pop();
if(c == '}' && temp != '{'|| c == ')' && temp != '('|| c == ']' && temp != ']'){
System.out.println("can not match in "+i);
}
}
}
while(!isEmpty()){
char c = pop();
if(c == '{'){
System.out.println("insert } to match "+charat(c));
}
if(c == '[' ){
System.out.println("insert ] to match "+charat(c));
}
if(c == '(' ){
System.out.println("insert ) to match "+charat(c));
}
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String string = s.nextLine();
Stack st = new Stack(string.length());
st.match(string);
}
result:
klsjdf(klj{lkjjsdf{)
can not match in 19
insert } to match 1
insert ) to match 0
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有