Linear Data Structures 1.8

Linear Data Structures 1.8 - Last Updated: 12-01-17 9:52 AM...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 36 - Example array-based stack in Java public class ArrayStack implements Stack { // holds the stack elements private Object S[ ]; // index to top element private int top = -1; // constructor public ArrayStack(int capacity) { S = new Object[capacity]); } public Object pop() throws EmptyStackException { if isEmpty() throw new EmptyStackException ( Empty stack: cannot pop ); Object temp = S[top]; // facilitates garbage collection S[top] = null; top = top 1; return temp; } Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 37 - Example Application: Parenthesis Matching Each (, {, or [ must be paired with a matching ), }, or [ correct: ( )(( )){([( )])} correct: ((( )(( )){([( )])} incorrect: )(( )){([( )])} incorrect: ({[ ])} incorrect: ( Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 38 - Parentheses Matching Algorithm Algorithm ParenMatch( X , n )...
View Full Document

Page1 / 5

Linear Data Structures 1.8 - Last Updated: 12-01-17 9:52 AM...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online