CS231 lecture notes, Fall 1998 Week 9, Wednesday Quiz 6 on tranforming object methods into class methods and vice versa. Review of syntax for constructors (using Stack as example) Global/class variables usually initialized at declaration Instance variables initialized in constructor. ----- Set the way-back machine... let's talk about the implementation of stacks and queues. Read notes14.txt and Standish 6.6 and 6.8. Also look at http://rocky.colby.edu/cs231/code/StackArray/ and http://rocky.colby.edu/cs231/code/StackList/ Let's see... I haven't provided implementations of Queues. Wouldn't that make an excellent exam question?!? ----- 1) Implementation of stacks a) using arrays b) using lists (this time the lists are implemented internally) Most of this is almost identical to the array implementation of PriorityQueue: public class Stack { private int count; private int capacity; private int capacityIncrement; private Object[] itemArray; public Stack () { count = 0; capacity = 10; capacityIncrement = 10; itemArray = new Object[capacity]; } public boolean empty () { return (count == 0); } public void push (Object obj) { if (count == capacity) { capacity += capacityIncrement; capacityIncrement *= 2; Object[] tempArray = new Object[capacity]; for (int i=0; i