Docsity

Practice Final Exam - Representing Structure and Behavior | CS 1316, Exams of Computer Science

Toggle sidebar
bg1
SUMMER 2007 CS1316 PRACTICE FINAL
STACK AND QUEUE METHODS (see reference sheet for method explanation)
A. STACK
1. For your stack, insertion occurs at the ____________ (first/last).
2. For your stack, removal occurs at the ____________ (first/last).
3. Implement the following methods for a stack according to your specifications for insertion
and removal (Assume the linkedlist of elements in the stack is called elements and is already
available to you):
a. public boolean isEmpty()
b. public Object pop()
c. public Object push(Object item)
B. QUEUE
1. For your queue, insertion occurs at the ____________ (first/last).
2. For your queue, removal occurs at the ____________ (first/last).
3. Implement the following methods for a queue according to your specifications for insertion
and removal (Assume the linkedlist of elements in the queue is called elements and is
already available to you):
a. public boolean isEmpty()
b. public Object pop()
c. public Object push(Object item)
pf2

Partial preview of the text

Download Practice Final Exam - Representing Structure and Behavior | CS 1316 and more Exams Computer Science in PDF only on Docsity!

SUMMER 2007 CS1316 PRACTICE FINAL

STACK AND QUEUE METHODS (see reference sheet for method explanation)

A. STACK

  1. For your stack, insertion occurs at the ____________ (first/last).
  2. For your stack, removal occurs at the ____________ (first/last).
  3. Implement the following methods for a stack according to your specifications for insertion and removal (Assume the linkedlist of elements in the stack is called elements and is already available to you): a. public boolean isEmpty()

b. public Object pop()

c. public Object push(Object item)

B. QUEUE

  1. For your queue, insertion occurs at the ____________ (first/last).
  2. For your queue, removal occurs at the ____________ (first/last).
  3. Implement the following methods for a queue according to your specifications for insertion and removal (Assume the linkedlist of elements in the queue is called elements and is already available to you): a. public boolean isEmpty()

b. public Object pop()

c. public Object push(Object item)

SUMMER 2007 CS1316 PRACTICE FINAL

REFERENCE SHEET (STACK AND QUEUE METHODS)

LinkedList Method Summary

void addFirst(Object o) Inserts the given element at the beginning of this list. void addLast(Object o) Appends the given element to the end of this list. Object getFirst() Returns the first element in this list. Object getLast() Returns the last element in this list. Object removeFirst() Removes and returns the first element from this list. Object removeLast() Removes and returns the last element from this list. int size() Returns the number of elements in this list.

Stack Method Summary

boolean isEmpty() Tests if this stack is empty. Object pop() Removes the Object at the top of this stack and returns that Object. Object push(Object item) Pushes an item onto the top of this stack.

Queue Method Summary

boolean isEmpty() Tests if this queue is empty. Object pop() Removes the Object at the front of the list and returns that Object. Object push(Object item) Adds an item at the front of the list.