Introduction to Data Structures

# Introduction to Data Structures - Introduction LinkedList...

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

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

View Full Document
arrayA[4] = 50; System. out .println(arrayA. length ); int [] arrayB = new int [6]; int i = 0; for (i = 0; i < arrayA. length ; i++) arrayB[i] = arrayA[i]; arrayB[i] = 60; arrayA = arrayB; System. out .println(arrayA. length ); } } Output

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

View Full Document
Stacks and Queues Stacks A stack consists of a sequence of items, which should be thought of as piled one on top of the other like a physical stack of boxes or cafeteria trays. Only the top item on the stack is accessible at any given time. It can be removed from the stack with an operation called pop. An item lower down on the stack can only be removed after all the items on top of it have been popped off the stack. A new item can be added to the top of the stack with an operation called push. We can make a stack of any type of items. If, for example, the items are values of type int, then the push and pop operations can be implemented as instance methods void push (int newItem) -- Add newItem to top of stack. int pop() -- Remove the top int from the stack and return it. It is an error to try to pop an item from an empty stack, so it is important to be able to tell whether a stack is empty. We need another stack operation to do the test, implemented as an instance method boolean isEmpty() -- Returns true if the stack is empty. Queues
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

Introduction to Data Structures - Introduction LinkedList...

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

View Full Document
Ask a homework question - tutors are online