Created
November 4, 2013 22:17
-
-
Save MosheBerman/7310145 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This class extends the Stack | |
* so that there's a pushdown(i) | |
* method which copies the elements | |
* at index 0 and inserts it and index i. | |
* All items beneath index i are pushed down. | |
* | |
*/ | |
import java.util.Stack; | |
public class ExtendedStack extends Stack { | |
@SuppressWarnings("unchecked") | |
public static void main(String[] args) | |
{ | |
ExtendedStack e = new ExtendedStack(); | |
e.push(1); | |
e.push(2); | |
e.push(42); | |
e.push(1); | |
} | |
public void pushdown(int i) | |
{ | |
this.insert(i, this.peek()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment