1)Given a singly linked list contains four nodes and simply show as 4->3->2->1, where the head reference refers to the first node contains an Integer with value 4. If Node curr = head; curr= curr.next; are applied to this list, what is the number you can find in the first node?
2)
Given a singly linked list contains 6 nodes, which is simply shown as 1->2->3->4->5->6. Assume head refers to the first node (contains 1) on the list. How many nodes remain on the list if the following statements are applied?
Node curr = head.next;
while(curr!=null)
{
if(curr. element % 2==0) curr = curr.next;
else curr.element++;
}
head = curr;
3)
Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the value that you can find in the second node of the remaining list if the following statements are applied? Assume head reference refers the first node of the list.
Node prev = head;
Node curr = head. next;
while(curr.next!=null)
{
if(prev.element > 3)
{
prev = curr;
curr = curr.next;
}
else break;
}
head = prev.next;
1)Given a singly linked list contains four nodes and simply show as 4->3->2->1, where the head reference refers to the first node contains an Integer with value 4. If Node curr = head; curr= curr.next; are applied to this list, what is the number you can find in the first node?
Ans:
let start node address is 100, and the next node address is 200, and so on.
4->3->2->1
4 is address 100, 3 at address 200, 2 at address 300.
head=100
curr=head //100
curr=curr.next //200
here we have changed the curr to the next location. but the head is not changed.
so head points to 1st node that is 4, and curr points to second node that is 3.
============================================================================================
2)
Given a singly linked list contains 6 nodes, which is simply shown as 1->2->3->4->5->6. Assume head refers to the first node (contains 1) on the list. How many nodes remain on the list if the following statements are applied?
Node curr = head.next;
while(curr!=null)
{
if(curr. element % 2==0) curr = curr.next;
else curr.element++;
}
head = curr;
Ans:

so head=null
there will be node in the list.
============================================================================================
3)
Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the value that you can find in the second node of the remaining list if the following statements are applied? Assume head reference refers the first node of the list.
Node prev = head;
Node curr = head. next;
while(curr.next!=null)
{
if(prev.element > 3)
{
prev = curr;
curr = curr.next;
}
else break;
}
head = prev.next;
Ans:

1)Given a singly linked list contains four nodes and simply show as 4->3->2->1, where the head...
Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the value that you can find in the second node of the remaining list if the following statements are applied? Assume head reference refers the first node of the list. Node prev = head; Node curr = head. next; while(curr.next!=null) { if(prev.element > 3) { prev = curr; curr = curr.next; } else break; } head = prev.next; Question 3 options: 3 2 4 1...
Question 2 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the last node when the following operations are executed? head->1111-151->11011->1211 Node curr = head; while(curr next !=null) { curr.item = curritem-head. item; curr = cur next; اسرة Node newNode = new Node(8): curr.next = newNode: 23 O 12 OS O21 Question 3 (3 points) Given a recursive method as shown below, what is the return value for P(5)...
True False Question 2 (3 points) Given a singly linked list with more than two nodes, to remove the second node from a linked list with only head reference, assume curr - head, next, you do Set curr.next to head.next Oset head. next to curr.next Set head, next to curr Oset head to curr.next TL th Question 3 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the last...
C++: I need implement this code using Double Linked List using the cosiderations 1. head point to null in an empty list 2. There is not need of a tail pointer /*This class implements the singly linked list using templates Each list has two attributes: -head: first node in the list -tail: last node in the list #include "circDLLNode.h" template class { public: //Default constructor: creates an empty list (); //Destructor: deallocate memory ~(); ...
Question 13 (6 points) Assume the singly linked list is defined as a head reference variable refers to the first node and a size reference variable refers to the number of nodes (similar like your L.AB4). Provide a method named count that used to count and return the occurrences of the head item (item stored at the head node) in the list. If the list is empty, return - 1. provide the appropriate method signature and implementation. Format BIU In...
Data Structures - Singly Linked Lists You will add a method swapNodes to SinglyLinkedList class (below). This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same node, etc. Write the main method to test the swapNodes method. You may need to traverse the list. package linkedlists; public class SinglyLinkedList<E> implements Cloneable { // ---------------- nested Node class...
Question: SWAPPING NODES IN A SINGULARLY LINKED LIST: I am attempting to create a program that swaps 2 nodes (no matter where they are in the list) and am having some difficulty. I can't seem to figure out why this swap method is throwing an error. Code: (SWAPPING METHOD AND TEST LINE BOLDED) package linkedlists; public class SinglyLinkedList<E> implements Cloneable { //---------------- nested Node class ---------------- /** * Node of a singly linked list, which stores a reference to its...
14) Create a singly linked list using only two variables: head and current. Traverse through the list void addToEnd (struct node *&head, int data){ //create node //if head==NULL //else } int main (){ node * head=NULL; addToEnd(head,1); addToEnd(head,2); addToEnd(head,3); //Traverse using current }
Answer all questions
1- in circular singly linked list, previous pointer of the first node points to which node A. First node B. Itself C. null D. Last node 2- Which of the following is NOT an applications of linked lists? A. Implementation of stacks and queues B. Dynamic memory allocation C. Manipulation of polynomials D. Keeping people at home during epidemics like corona virus 3- In a circular singly linked list? A. Components are all linked together in some...
C++
You're given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. The lists are equal only if they have the same number of nodes and corresponding nodes contain the same data. Either head pointer given may be null meaning that the corresponding list is empty. Input Format You have to complete the int CompareLists (Node headA, Node* head B) method which takes...