0% found this document useful (0 votes)
19 views

Lab Exercise (1)

Uploaded by

ameeraroslan550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lab Exercise (1)

Uploaded by

ameeraroslan550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4 CD/JUL 2024/CSC248

QUESTION 2

a) In programming and computer science, stacks are frequently used in a variety of


applications.

i) Describe how stack is different than other data structures and give TWO examples of
stack application in computer system.
(5 marks)

ii) RS Entertainment has launched a new online music player for Android users as
illustrated in Figure 1. The application will automatically add any trending songs in
Malaysia to the playlist so that it can be listened by users. The Stack concept was
applied to the application's playlist.

RS Music Player / /x
UiTM DiHatiku
UiTM Choir

O M - o

_ _ . 227 4» -a
(£) G4. UiTM DiHatiku - UiTM Choir 2.35

© G3. Sinaran Mentari - Jay CHU 3.43

© G2. Bersama Menggapai Impian - Sufi Banda 3.32

Figure 1

The following class Song was used for storing information about songs that contains
data such as song's title, singer's name, and length of the song.

© Hak Cipta Universiti Teknologi MARA


5 CD/JUL 2024/CSC248

Assume that all data have been inserted into a s t a c k object named p l a y L i s t .

public class Song


{
private String title; //title of song
private String singer; //singer's name
private double length; //length of song in minutes
/**
Definition of methods including a normal constructor,
accessors, and a toStringO printer
** /

}
public class Stack
{
public Stack () { ... }
public void push (Song ...) { ... }
public Song pop () { ... }
public Song peek() { ... }
public boolean isEmptyO { ... }
J
Write a program segment to compute and display the total length of all songs
performed by the uiTM c h o i r . (Note: use a temporary stack to store the information
to avoid data loss.)
(5 marks)

iii) Write a program segment to display information of all songs where the title starts with
T and length of the song is greater than 3 minutes. (Note: use a temporary stack to
store the information to avoid data loss.)
(5 marks)

b) Given the following expression:

A - P + A / T + H * ( E - T $ I + C)

Convert the given expression into the following notation along with the steps.

i) Prefix
(5 marks)

ii) Postfix
(5 marks)
c) Given the following infix expression:

Z-(E$A*L + 0)*U/S

© Hak Cipta Universiti Teknologi MARA

You might also like