Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class testClass {
- public static boolean isIncreasing(Stack<Double> st){
- Stack<Double> tmp=new LinkedListStack();
- boolean res=true;
- while (st.getSize()>0){
- try{
- tmp.push(st.pop());
- } catch(Exception ex){
- System.out.println(ex.getMessage());
- }
- }
- if (tmp.getSize()>0){
- double prev;
- try{
- prev=tmp.pop();
- st.push(prev);
- } catch(Exception ex){
- System.out.println(ex.getMessage());
- prev=0.0;
- }
- while (tmp.getSize()>0){
- try{
- double newDouble=tmp.pop();
- if (res && newDouble<prev){
- res=false;
- }
- prev=newDouble;
- st.push(prev);
- } catch(Exception ex){
- System.out.println(ex.getMessage());
- }
- }
- }
- return res;
- }
- public static void main(String[] args){
- Stack<Double> st=new LinkedListStack();
- for (double i=1.0; i<=12.0; i=i+1.0){
- st.push(i);
- }
- System.out.println(isIncreasing(st));
- System.out.println(st+"\n");
- st.push(1.0);
- System.out.println(isIncreasing(st));
- System.out.println(st);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment