Question

In: Computer Science

1. What is output by the following C++ code segment? Assume myList is an initially empty...

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:

Solutions

Expert Solution

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.


Related Solutions

21. What is the output of the following segment of code if 7 is input by...
21. What is the output of the following segment of code if 7 is input by the user when asked to enter a number?____________ int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 7: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout...
no need to explain 11. What is output by the following code segment? boolean isHighTemp =...
no need to explain 11. What is output by the following code segment? boolean isHighTemp = true; double degree = 100.01; if (isHighTemp) if(degree >= 110) System.out.print(“Extremely Hot”); else System.out.println(“Not Hot”); A) Extremely Hot B) Not Hot C) Hot D) Extremely Hot Not Hot 12. To produce the output 2 4 6 8 10, what is the loop condition for the following loop? int n = 0; Page 3 do { n = n + 2; System.out.print(n + “ ”);...
what is the expected output of the following segment of code? dq = Deque() dq.push_back('M') dq.push_back('...
what is the expected output of the following segment of code? dq = Deque() dq.push_back('M') dq.push_back(' ') l = ['A', 'L', 'E', 'S', 'T', 'E'] for i in l: → if ord(i) % 3 == 0: → → dq.push_back(i) → elif ord(i) % 5 == 0: → → dq.push_front(i) → → dq.push_back(i) → elif ord(i) % 4 == 0: → → dq.push_back(i) → else: → → dq.peek_front() → → dq.push_front('X') → → dq.push_back('R') dq.push_front(dq.peek_back()) dq.pop_back() print(dq)
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.int count = 0;do{++ count;if (count == 2)Blank;cout << count << " ";} while (count <= Blank);cout << endl;
Given the following code segment, tell the output if it is part of an executable program....
Given the following code segment, tell the output if it is part of an executable program. Assume the addresses of the variables, a and b, are 0012A32A and 0012A340, respectively.        int* intPtr1, *intPtr2;        int a = 10, b;        intPtr1 = &a;        cout<< "The data in a is "<<a<<endl;        cout << "The address of a is "<<&a<<endl;        cout <<"The data in intPtr1 is "<< intPtr1 <<endl;        cout <<"The data in the variable pointed by...
What is the output from each of the following segments of C++ code? Record the output...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 8; j > 3; j -= 2)         cout << setw(5) << j;     Answer:      2. int sum = 5;    for (int k = -4; k <= 1; k++)         sum = sum...
Write assembly code for the following machine code. Assume that the segment is placed starting at...
Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual memory addresses represented by such labels. 0010 1010 0000 1000 0000 0000 0000 1010 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0001 0001 1000 0000 0010 0000 0000 1000 0000 0000 0100 1110 0010 0101 0000 0010 0001 0010 1000 0000 0010 0000
a. Write machine code for the following assembly code. Assume that the segment is placed starting...
a. Write machine code for the following assembly code. Assume that the segment is placed starting at location 80000. Use decimal numbers to represent each instruction. loop:         beq $s3, $s1, endwhile                  add $t0, $s3, $s4                  lw $t1, 0($t0)                  add $s0, $s0, $t1                  addi $s3, $s3, 4                  j loop endwhile: b. Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual...
What would the output be for the following program code segment? #define ROWS  3      #define COLS 3...
What would the output be for the following program code segment? #define ROWS  3      #define COLS 3 void addCoulmns(int arr[][COLS],int Sum[COLS]); int main(void) {        int array[ROWS][COLS] = {{ 10, 35, 23 },                                   { 5, 4, 57 },                                   { 4, 7, 21 }};        int ColSum[ROWS];        int rows;        int columns;        addCoulmns(array,ColSum);        for (columns = 0; columns < COLS - 1; columns++)               printf("%d\n",ColSum[columns]);        return(0); } void addCoulmns(int arr[][COLS],int Sum[COLS]) {        int row;        int col;        for (col = 0; col < COLS -...
You will implement the MyList ADT according to the following: 1. MyList must implement the List...
You will implement the MyList ADT according to the following: 1. MyList must implement the List interface. It will look something like below: public class MyList<E> implements List<E> { ... } Note: As said in the class, when implementing an interface, you have to implement each method in it. There are a lot of methods in the List interface. We are going to address this issue below. 2. The initial capacity of MyList must be 2. This is not an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT