1. Let q be a stack. Consider the following program: q.enqueue(1); q.enqueue(2);
ID: 667392 • Letter: 1
Question
1. Let q be a stack. Consider the following program:
q.enqueue(1);
q.enqueue(2);
q.dequeue();
q.enqueue(3);
q.enqueue(4);
q.dequeue();
int x = q.getFront();
What is the value displayed by the System.out.println statement?
2. Consider a class ClassName whose methods are listed below. What class is it?
ClassName(){...}
boolean isEmpty(){...}
void display(){...}
boolean search(int x){...}
void insert(int i){...}
void remove(int x){...}
3. Let s be a stack. Consider the following program:
s.push(1);
s.push(2);
s.push(3);
s.pop();
s.push(4);
s.pop();
s.pop();
int x = s.peek();
What is the value of x after the assignment statement?
4. If a binary search is applied to an array with 1024 elements, in the worst case the main loop executes, approximately, ____.
Explanation / Answer
1. Let q be a stack. Consider the following program:
q.enqueue(1);
q.enqueue(2);
q.dequeue();
q.enqueue(3);
q.enqueue(4);
q.dequeue();
int x = q.getFront();
What is the value displayed by the System.out.println statement?
ANS)
q.enqueue(1); 1
q.enqueue(2); 1,2
q.dequeue(); 1
q.enqueue(3); 1,3
q.enqueue(4); 1,3,4
q.dequeue(); 1,3
int x = q.getFront();
x=3
2. Consider a class ClassName whose methods are listed below. What class is it?
ClassName(){...}
boolean isEmpty(){...}
void display(){...}
boolean search(int x){...}
void insert(int i){...}
void remove(int x){...}
ANS)LinkedList
3. Let s be a stack. Consider the following program:
s.push(1);
s.push(2);
s.push(3);
s.pop();
s.push(4);
s.pop();
s.pop();
int x = s.peek();
ANS)
s.push(1); 1
s.push(2); 1,2
s.push(3); 1,2,3
s.pop(); 1,2
s.push(4); 1,2,4
s.pop(); 1,2
s.pop(); 1
x=s.peek1
What is the value of x after the assignment statement?
x=1
4. If a binary search is applied to an array with 1024 elements, in the worst case the main loop executes, approximately, _512___.(1024/2) times
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.