[30 marks] Use the linked list pictured below to answer the following questions:
ID: 3600222 • Letter: #
Question
[30 marks] Use the linked list pictured below to answer the following questions: 2000 1000 1600 istDat 1000 1600 17 NULL .inio .next list ptr2 a) Write a single line of code to test if the list is empty [2 marks] b) Give the value of the following statements: If the statement is invalid, explain why. [12 marks] 11) 111) IV) v) vi) vii) ptr1->next = ptr1->next->info = ptr2.>info = ptr2->next->next = pt12->info->next = ptr2->next->next->info = Redraw the list after executing each of the following set of statements temp= new NodeType: temp->info = 120. temp->next = ptr->next; ptr2->next=temp; c) Write a C+t code of a function calledPutem) of the SortedList class (shown below) to perform a conditional insertion. The insertion is only to be made if an item with the same key is not already in the list. A boolean reference parameter, ItemExists, is set to indicate if the item is already in the list. You are given on the next page the Putltem method of the SortedList class [16 marks] without the conditional insertion. Activate WindoExplanation / Answer
a) listData is head node, which is pointing to first node of the list,
to test if the list is empty or not, check if head node is empty or not
therefore, the single line code is
if(listData==NULL)
printf("List is Empty ");
b)
i) ptr1 is pointing to first node, first node contains 5 as info and next node's
address 1000 in next.
therefor ptr1->next will be print 1000
ii) ptr1->next is 1000, which is second node. second contains 14 as info and next
node's address 1600 in next.
ptr1->next->info will print 14 as output
iii) ptr2 is pointing to second node, which is 14 as info and next node address
1600 as info.
ptr2->info will print 14 as output
iv) ptr2->next is 1600, which is 3rd node, it contains 17 as info and NULL
as next. so, ptr2->next->next will print NULL as output
v) ptr2->info will be 14 but 14->next is invalid, bcz 14 is a int value
not address of next node. so ptr2->info->next is invalid
vi) ptr2 is second node, ptr2->next is 3rd node, ptr2->next->next will be 4th
node, but there are no more nodes, so ptr2->next->next is NULL.
ptr2->next->next->info is invalid. because, there is no node, how can we print
info in that node. so invalid
vii)
//temp is a new node
NodePtr temp
temp = new NodeType
//temp node have 150 as info
temp->info=150
//ptr2 is 2nd node, ptr2->next is 1600
//1600 will stored in temp->next
//that means new node temp is pointing to 3rd node
temp->next = ptr2->next
//ptr2, that is 2nd node is also still pointing to 3rd node
//now
//new node temp's address will be stored in ptr2's next
//now ptr2, 2nd node is pointing to new node temp
ptr2->next = temp
//clearly, after executing this code, a new node with info as 150
//is added between second node and 3rd node.
//so, the list is 5->14->150->17->NULL
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.