Question

In: Computer Science

After the code executes (in C++), what will the linked list 8->4->3->7->5 look like? (8 is...

After the code executes (in C++), what will the linked list 8->4->3->7->5 look like? (8 is the head)

1a)

Node* newNode = new Node(26);
newNode->next = head->next;
head = newNode;

1b)

Node* curNode = head;
for(int i=0; i<2; i++)
curNode = curNode->next;
Node* temp = curNode->next;
curNode->next = curNode->next ->next;
delete temp;
temp = nullptr;

Solutions

Expert Solution

Given Linked list:-

8->4->3->7->5

1a) Given Code:-

Node* newNode = new Node(26);
newNode->next = head->next;
head = newNode;

After execution of the above code, newNode is created with data field:- 26 and address field is assigned with the address of the second node(i.e the node having data value 4). After this, the address of the new node is assigned to head Node. So, indirectly the new node comes before the node having data value 4.

So, the final list is:-

8->26->4->3->7->5

1b) Given Code:-

Node* curNode = head;
for(int i=0; i<2; i++)
curNode = curNode->next;
Node* temp = curNode->next;
curNode->next = curNode->next ->next;
delete temp;
temp = nullptr;

In the above code, curNode is assigned with the address of head. Now the for loop will run twice and after execution of loop. The curNode is pointing to a node having data value 4.

After this, the temp will point to the node having data value 7. Now, the address field of curNode is assigned with the address of node having data value 7, and the temp is deleted. Due to this node having value 3 is deleted from the list.

So, the final list is:-

8->26->4->7->5


Related Solutions

A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5] D = [1, -9, 5, -3] E = [3, 3, -1] Uz = 1/|z| ^z d(X,Y) = (Rθ) d = diameter R = Radius θ = Theta Find a. Uc b. d (D, C) c. Let P = B + 3E, UP = d. A x B e. 3B x E f. C x D
Please use C++ and linked list to solve this problem Linked list 1 -> 3 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next = p;     } };...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7 9 7 4 6 9 9 -5.48x + 0.17 5.48x + 0.17 -0.17x + 5.48 0.17x + 5.48
a = [3, -4, 7] b = [-6, 9, 8] c = [4, 0, 8] d...
a = [3, -4, 7] b = [-6, 9, 8] c = [4, 0, 8] d =[7, 1, 7] e = [3, -5, 2, 1] f =[5, -7, -3, 6] g = [3, -4, 4, 3] P = Projection of ex. C = |g|(gf/gf) C = gf/|f| ex. P g --> f = Cgf = C(gf/f) (1/|f|) (f) =( gf/ff)(f) Find a. Pg --> f b. Pa --> 3b + e Find (cross multiply) a. ||a X b|| b. ||g...
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question...
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question 's scores, If three points were added to every score in this distribution, what would be the new mean? If three points were added to every score in this distribution, what would be the new standard deviation. Remember, you have already calculated population standard deviation in a previous problem. This problem requires two answers.
Python programming question: Suppose i have a list like: ['a:10', 'b:9', 'c:8', 'd:7', 'e:6', 'f:5', 'g:4',...
Python programming question: Suppose i have a list like: ['a:10', 'b:9', 'c:8', 'd:7', 'e:6', 'f:5', 'g:4', 'h:3', 'i:2', 'j:1', 'k:0'] How do i trans form this into a dictionary or something i can plot a graph with using these keys and value pairs? thanks.
Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C,...
Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. How many hexadecimal strings of length twelve have five A’s and five B’s? How many hexadecimal strings of length twelve have at most three E’s? How many hexadecimal strings of length twelve have exactly three A’s and at least two B’s? How many hexadecimal strings of length twelve have exactly two A’s and exactly two B’s, so that the two...
n = 8 measurements: 5, 3, 6, 7, 6, 5, 4, 7 Calculate the sample variance,...
n = 8 measurements: 5, 3, 6, 7, 6, 5, 4, 7 Calculate the sample variance, s2, using the definition formula. (Round your answer to four decimal places.) s2 = Calculate the sample variance, s2 using the computing formula. (Round your answer to four decimal places.) s2 =   Find the sample standard deviation, s. (Round your answer to three decimal places.) s =
Consider the following. n = 8 measurements: 4, 3, 7, 8, 5, 6, 4, 6 Calculate...
Consider the following. n = 8 measurements: 4, 3, 7, 8, 5, 6, 4, 6 Calculate the sample variance, s2, using the definition formula. (Round your answer to four decimal places.) s2 = Calculate the sample variance, s2 using the computing formula. (Round your answer to four decimal places.) s2 = Find the sample standard deviation, s. (Round your answer to three decimal places.) s =
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8...
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8 −9 6) (1) Count the number of rows that contain negative components. (2) Obtain the inverse of A and count the number of columns that contain even number of positive components. (3) Assign column names (a,b,c,d) to the columns of A. (4) Transform the matrix A into a vector object a by stacking rows. (5) Replace the diagonal components of A with (0,0,2,3). Hint:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT