In: Computer Science
1. What is output by the following C++ code segment? Assume myList is an initially empty linked list that can store floats. Draw the linked list (with head, nodes, and pointers) to show how it looks conceptually by the time the code completes executing.
FloatList myList;
myList.insertNode(5.25);
myList.insertNode(2.14);
myList.appendNode(9.11);
for (int x = 1; x < 4; x++)
myList.insertNode(x * 0.1);
myList.deleteNode(2.14);
myList.displayList();
Output:
Linked list drawing:
Given Code:-
FloatList myList;
myList.insertNode(5.25);
myList.insertNode(2.14);
myList.appendNode(9.11);
for (int x = 1; x < 4; x++)
myList.insertNode(x * 0.1);
myList.deleteNode(2.14);
myList.displayList();
1) myList.insertNode(5.25);
head----> 5.25---->Null
2) myList.insertNode(2.14);
head----> 2.14 ---->5.25---->Null
3) myList.appendNode(9.11); //append will add the node at the last of list
head----> 2.14---->5.25---->9.11---->Null
4) for (int x = 1; x < 4; x++)
myList.insertNode(x * 0.1);
head---->0.1---->2.14---->5.25---->9.11---->Null
head---->0.2---->0.1---->2.14---->5.25---->9.11---->Null
head---->0.3---->0.2---->0.1---->2.14---->5.25---->9.11---->Null
5) myList.deleteNode(2.14);
head---->0.3---->0.2---->0.1---->5.25---->9.11---->Null
6) myList.displayList();
head---->0.3---->0.2---->0.1---->5.25---->9.11---->Null (Final linked list)
0.3 0.2 0.1 5.25 9.11 (Final linled list will display like this)
Thank You....!!!!
For any query, please comment.