Tutorial_8_v02-for-viewing-printing

Tutorial_8_v02-for-viewing-printing - CC2203 Data...

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

View Full Document Right Arrow Icon
CC2203 Data Structures and Algorithms Sem 2, 2009-2010 Tutorial 8 Instruction In this tutorial, you are required to submit your tutorial work answer for the exercise to me. Tutorial work will not be graded unless your coursework fails (coursework below D grade). If one’s coursework fails, that tutorial work will be graded to see if condone pass should be issued or not. Exercise 1 Given the following Java code: public class StackTest { public static void print(Stack s) { String str = "["; if (s.size() >= 1) { for (int i = 0; i < s.size() - 1; i++) str += s.elementAt(i) + ", "; str += s.elementAt(s.size() - 1); } str += "]"; System.out.println(str); } public static void main(String[] args) { Stack s = new Stack(); s.push("10"); print(s); s.push("18"); print(s); s.push("14"); print(s); System.out.println("Peek " + s.peek()); print(s); System.out.println("Pop " + s.pop()); print(s); s.push("21"); print(s); System.out.println("Pop " + s.pop()); print(s); System.out.println("Pop " + s.pop()); print(s);
Background image of page 1

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

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

This note was uploaded on 08/18/2011 for the course COMP 3868 taught by Professor Keithchan during the Summer '97 term at Hong Kong Polytechnic University.

Page1 / 3

Tutorial_8_v02-for-viewing-printing - CC2203 Data...

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

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