**Interactive Slope of a line. Click and drag points to see formula in action


A+    A−    B  
Home
Algebra
Math Games
  • Decimals in Space
  • Fraction Balls
  • Integers in Space
  • Math Man
  • Number Balls
  • Geometry
    Interactive
    Trigonometry
    Jobs
  • Tutoring jobs
  • New York Tutoring Jobs
  • White Plains, NY
  • Westchester County, NY
  • Chicago Math Jobs
  • Philadelphia
  • Teacher Resources
    On FaceBook!

    Stack Data Type

    Import java.util.stack;

    To get a feel for some of the methods of the Stack. Run the code from this webpage.

    Strack Programming Exercises

    • Exercise 1) Write your own pared down version of the Stack class. This class should have the following methods . Refer to the quick reference to see what these methods should do and return. You may want to use an Object[] array to hold Stack elements. When the array fills up, allocate an array of twice the size and copy the values to the larger array.
      • push(E Object)
      • pop()
      • peek()
      • isEmpty();

    Programming Projects involving Stacks



    Project 1) Make the isPlandrome() method below work using only 1 Stack and no other data structures
    
    
    
    import java.util.Stack;
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    
    public class Palindrome2Student {
    
    public static Stack<Character>stack= new Stack();
    
    public static void main(String args[]){
    String word= JOptionPane.showInputDialog("Type in a potential palindrome");
    int lenght;
      
    System.out.println(isPalindrome(word));
    }
    
    public static boolean isPalindrome(String stringToParse){
    	
    	
    	int length = stringToParse.length();
    	
    	
    	for (int i =0;i < length;i++){
       System.out.println("Pushing in: "+ stringToParse.charAt(i)); 
    				
    	stack.push(stringToParse.charAt(i));
    	
    	}
       System.out.println("________________________");
    	for (int i =0;i < length;i++){
       System.out.println("Popping out : "+stack.pop()); 
    
    	}
    	
    
    	return false;
    	}
    
    }
    	  
    


    solution



    Project 2) Write a class that ensures that brackets, curley braces and parentheses are properly closed. This class should work for nested delimiters.

    Using stack to check matching delimiters

    Examples:

    1. c[d] // correct
    2. a{b[c]d}e // correct
    3. a{b(c]d}e // not correct; ] doesn't match (
    4. a[b{c}d]e} // not correct; nothing matches final }
    5. a{b(c) // not correct; Nothing matches opening {


    solution



    Top