Linear Data Structures 1.8

# Linear Data Structures 1.8 - Last Updated 9:52 AM CSE 2011...

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

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

View Full Document

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

View Full Document
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

## This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

### Page1 / 5

Linear Data Structures 1.8 - Last Updated 9:52 AM CSE 2011...

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

View Full Document
Ask a homework question - tutors are online