Title | Perfect size and oversize arrays |
---|---|
Author | Olivia Cobble |
Course | Introduction to Computer Programming |
Institution | University of Oklahoma |
Pages | 1 |
File Size | 36.3 KB |
File Type | |
Total Downloads | 42 |
Total Views | 156 |
Dr. Trytten's lecture about perfect size and oversize arrays....
Perfect Size and Oversize Arrays
Properties of Arrays o Homogeneous o Objects (only string so far) or primitive data o Sequential o Contents are zero indexed o length is data and is unit indexed o You cannot resize them Sometimes you know the perfect size for an array in advance (but not a lot) o If the size has to change, the array must be reconstructed String[] split(String source) o Splits source using whitespace (using Scanner) o Must be perfect size array Perfect size array logic o Size must first be calculated, and then the array is constructed o Method must return the array reference o Method cannot return array size o No reason to pass array reference as a parameter (since you’re constructing an array) Sometimes array size is not known or changes during program execution o Strategy: make the array too big, and keep track of size in separate variable o Split method: problem because you need to return the size and array Return size, pass in array Size cannot be a parameter because it is an int and it can’t be changed o Array must be constructed beforehand, only thing returned from method is the size Stack: Last in, first out o Push: adding things to stack end o Pop: removing from stack end...