You are on page 1of 3

SCHOOL OF INFORMATION TECHNOLOGY

General Luna Road, Baguio City Philippines 2600

Telefax No.: (074) 442-3071 Website: www.ubaguio.edu E-mail Address: ub@ubaguio.edu

DATA STRUCTURES AND ALGORITHM (DSALGO1) Laboratory


1st Semester SY 2020-2021 SCORE
Midterm Examination
Name: ______________________________ Section: _______
_____
60
Program Tracing / Simulation.

A) LINKED LIST
//PROGRAM 1 (30 points)
OUTPUT:
Original list:
12
Updated List:
132
Updated List:
1342
B. STACK

//PROGRAM 2 (10 points) What does the code fragment do?


Stack stack = new Stack(); Solution: prints the binary representation
while (n > 0) //n = 50 of n (110010 when n is 50).
{ stack.push(n % 2);
n /= 2;
}
while (!stack.isEmpty())
System.out.print(stack.pop());
System.out.println();

//PROGRAM 3 (20 points)

OUTPUT:
Top element is: D
C is present at 2 positions from top
Stack size is 2
Stack is not Empty

Prepared by: Reviewed by:

Cherry Ann C. Carpiso, MIT Hydi D. Toyeng, MIT Vanessa M. Vallejo, MIT
Program Chair, BSCS Program Chair, BSIT

You might also like