A clarification regarding the first stack homework
You don't want to just use the existing stack class, which Java already has. You want to write your OWN stack class, and then demonstrate it using your driver program.
you might also want an isFull method, which for a fixed size array will let you know whether you are near the capacity, and a size method, to return the present size. here are two ways you could clear the array:
1) don't. just reset the top of the stack to 0. the array is never being reallocated anyway. 2) since it is a reference to an array on the heap, set it to a new array on the heap. theArray = new int[100]; of course, you would still need to set the top of the stack to be 0, so you are not really gaining anything from this.
i sent u an email via blackboard, did you get it professor?
ReplyDeletenope. i'll check my qc email now. in general, the fastest way to reach me is as my name, as it appears in this comment, @gmail.
ReplyDeletejust checked it, and responded, as follows:
ReplyDeleteyou might also want an isFull method, which for a fixed size array will let you know whether you are near the capacity, and a size method, to return the present size.
here are two ways you could clear the array:
1) don't. just reset the top of the stack to 0. the array is never being reallocated anyway.
2) since it is a reference to an array on the heap, set it to a new array on the heap. theArray = new int[100]; of course, you would still need to set the top of the stack to be 0, so you are not really gaining anything from this.
all the best,
josh