Skip to content

Instantly share code, notes, and snippets.

@MosheBerman
Created November 4, 2013 22:17
Show Gist options
  • Save MosheBerman/7310145 to your computer and use it in GitHub Desktop.
Save MosheBerman/7310145 to your computer and use it in GitHub Desktop.
/**
* 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