Data Structures Assignment: Linked Lists, Stacks, and Queues Concepts

Verified

Added on  2020/04/29

|4
|395
|426
Homework Assignment
AI Summary
This assignment provides solutions to problems involving fundamental data structures. Question 1 focuses on linked lists, including operations such as inserting and searching elements within the list. The solution includes pseudocode for these operations. Question 2 explores the behavior of stacks, demonstrating the output of stack operations. Question 3 presents a solution for converting a number to its binary representation using a stack. Finally, Question 4 introduces queue data structures, defining a `printJob` class and a `PrinterQueue` class, outlining the basic structure for managing print jobs within a queue. The solutions offer detailed explanations and code snippets to help understand the concepts.
Document Page
Question 1: Linked Lists
a) studentList
Data structure for list:
class student{
string ID
string name
int intake
char gender
student * next
}
student * startNode
b) i) predecessor: S073593
successor: S073677
ii) pseudocode:
DECLARE a student pointer
temp
assign temp.ID = S073600
assign temp.name = “Joyce
Chia”
assign temp.intake = ‘F’
assign temp.intake = 4
assign temp.next = pPre.next
assign pPre.next = temp
c) pseudocode:
assign pPre.next = pDel.next
assign pDel.next = NULL
delet pDel
d) BEGIN DisplayStudents( slist )
DECLARE a student pointer
temp
Assign temp = slist
DECLARE integer count as
0
WHILE temp is not NULL
PRINT all details of
temp on screen
assign temp =
temp.next
INCREMENT count
by 1
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
END WHILE
PRINT total number of
student as count
END DisplayStudents
e) BEGIN
DisplayFemaleStudents( slist )
DECLARE a student pointer
temp
Assign temp = slist
DECLARE integer count as
0
WHILE temp is not NULL
CHECK IF
temp.gender is ‘F’:
CHECK IF
temp.intake is 5 or 6 or 7:
PRIN
T all details
of temp on
screen
END IF
END IF
assign temp =
temp.next
INCREMENT count
by 1
END WHILE
PRINT total number of
student asount
END DisplayFemaleStudents
f) BEGIN SearchStudents( slist,
studID )
DECLARE a student pointer
temp
assign temp = slist
WHILE temp is not NULL
and temp.ID <= studID
CHECK IF temp.ID
is equal to studID
return temp
END IF
assign temp =
temp.next
END WHILE
Document Page
return NULL
END SearchStudents
g) Append two lists:
BEGIN append ( list1, list2 )
CHECK IF list1 is NULL
assign list1 = list2
OTHERWISE
DECLARE a student
pointer temp
assign temp = list1
WHILE temp.next is
not NULL
assign temp =
temp.next
temp.next = list2
END append
Question2: Stacks
OUTPUT:
15
30
3
10
Question3: Stacks
BEGIN ConvertToBinary( num )
CreateStack(A)
WHILE ( num is NOT 0)
assign temp = num%2
assign num = num/2
Push (A, temp)
END WHILE
WHILE ( NOT isEmpty(A) )
DISPLAY pop(A)
END WHILE
END ConvertToBinary
Question4: Queue
Document Page
Data Structures:
DECLARE class printJob
Integer queueNumber
String docName
Double docSize
printJob * next
END CLASS
DECLARE class PrinterQueue
printJob * firstJob
printJob * lastJob
Integer currentJobs
END CLASS
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]