Question

In: Computer Science

1- Given following data structure of Single linked list :           class ListNode                     &n

1- Given following data structure of Single linked list :

          class ListNode                        

           { int item ;                             

             ListNode next ;                        

             ….

           }

Choose the correct answer :                                                           

  1. Suppose reference refers to a node in a List (using the ListNode ) . What statement changes reference so that it refers to the next node?

                       1-      reference++ ;

2-    reference = next ;

3-    reference+= next ;

  1. reference = reference.next ;
  1. Suppose p refers to a node in a List (using the ListNode ) . What boolean expression will be true when p refers to the last node of the List?

1-   (p == null)

2- (p.next == null)

  1. (p.item == null)

4- (p.item == 0)

      5- None of the above.

  1. Which boolean expression indicates whether the items in two nodes (n and m) are the same. Assume that neither n nor m is null.

1-   n == m

2-   n.item == m.item

  1. n.next == m.next

4- None of the above

Solutions

Expert Solution

First Question:

Fourth option is the correct answer.

The following statement changes reference so that it refers to the next node:

reference = reference.next ;

First option is incorrect as it will not change reference so that it refers to the next node.

Second option is incorrect as it will not change reference so that it refers to the next node.

Third option is incorrect as it will not change reference so that it refers to the next node.

Second Question:

Second option is the correct answer.

When 'p' is referring to the last node of the list, then the 'next' pointer must be null as there is no more node. So, it will be:

(p.next == null)

First option is incorrect as this Boolean expression will not be true when 'p' refers to the last node of the list.

Third option is incorrect as this Boolean expression will not be true when 'p' refers to the last node of the list.

Fourth option is incorrect as this Boolean expression will not be true when 'p' refers to the last node of the list.

Fifth option is incorrect as the second option is true.

Third Question:

Second option is the correct answer.

The following Boolean expression indicates that the items in two nodes (n and m) are the same when both are not null:

n.item == m.item

First option is incorrect as this following Boolean expression does not indicate that the items in two nodes (n and m) are the same when both are not null.

Third option is incorrect as this following Boolean expression does not indicate that the items in two nodes (n and m) are the same when both are not null.

Fourth option is incorrect as the second option is true.

Please comment in case of any doubt.
Please upvote if this helps.


Related Solutions

C++ Using an appropriate definition of ListNode, design a simple linked list class with only two...
C++ Using an appropriate definition of ListNode, design a simple linked list class with only two member functions and a default constructor: void add(double x); boolean isMember(double x); LinkedList( ); The add function adds a new node containing x to the front (head) of the list, while the isMember function tests to see if the list contains a node with the value x. Test your linked list class by adding various numbers to the list and then testing for membership....
Python: Solve following problems using Linked List Data Structure 2. Create a Queue class. In the...
Python: Solve following problems using Linked List Data Structure 2. Create a Queue class. In the queue class create enqueue, dequeue, first, empty, len and resize methods. The class should support circular queue and have the ability to resize the queue.
Data structure program Implement (your own) the Radix Sort using single linked list java language
Data structure program Implement (your own) the Radix Sort using single linked list java language
Write a program to implement linked list data structure that will have following functions: a. Append...
Write a program to implement linked list data structure that will have following functions: a. Append a node in the list b. Insert a node in the list c. Delete a node from the list d. Display list e. Find maximum value in the list f. Find how many times a value exists in the list. g. Search Portion of the code is give below. You have to write code for the items (e, f, g) Program: #include<stdlib.h> #include<stdio.h> #include<iostream>...
Purpose Purpose is to implement some single linked list methods. Add methods to the List class...
Purpose Purpose is to implement some single linked list methods. Add methods to the List class In the ‘Implementation of linked lists’ lecture, review the ‘Dynamic implementation of single linked list’ section. You will be adding new methods to the List class. Eight new methods are required: new constructor – creates a new single linked list from an array of integers e.g. int a[] = {1, 2, 3, 4}; List list = new List(a); toString() – returns a string representing...
//LinkNode is a class for storing a single node of a linked list storing integer values....
//LinkNode is a class for storing a single node of a linked list storing integer values. It has two public data fields for the data and the link to //the next node in the list and has three constructors: public class LinkNode { public int data;       public LinkNode next; // post: constructs a node with data 0 and null link public ListNode() {      this(0, null); } // post: constructs a node with given data and null link public LinkNode (int...
C++ language or Python. Linked Lists You are given a linked list that contains N integers....
C++ language or Python. Linked Lists You are given a linked list that contains N integers. You are to perform the following reverse operation on the list: Select all the subparts of the list that contain only even integers. For example, if the list is {1,2,8,9,12,16}, then the selected subparts will be {2,8}, {12,16}. Reverse the selected subpart such as {8,2} and {16,12}. The list should now be {1,8,2,9,16,12}. Your node definition should consist of 2 elements: the integer value...
C++ coding functions Implement the following class using linked lists. Creating a simple linked list class...
C++ coding functions Implement the following class using linked lists. Creating a simple linked list class to use is probably your first step.(Please do not use collections like .push() . pop(), etc.) and instead create the implementation A templated stack class that stores type T with the following public functions: - void Push(T t) - adds t to the top of the stack - T Pop() - asserts that the stack is not empty then removes and returns the item...
Class GroceryBag collects instances of class Item in an appropriate data structure.                       Class Item      &n
Class GroceryBag collects instances of class Item in an appropriate data structure.                       Class Item                 ---------------------------                -String description                -int cost   //price in cents                ----------------------------                + [constructor, getters, and a toString() method] •         (Assume class Item has already been coded)                       Class GroceryBag (Highlights)                ----------------------------------                  -bag   // an ArrayList of <Item>                ----------------------------------                   assume public methods: constructor, totalBag(), findItem(String it), listAll(), etc. •         The ONLY thing you need to do in the space below is to...
You are given a singly linked list. Write a function to find if the linked list...
You are given a singly linked list. Write a function to find if the linked list contains a cycle or not. A linked list may contain a cycle anywhere. A cycle means that some nodes are connected in the linked list. It doesn't necessarily mean that all nodes in the linked list have to be connected in a cycle starting and ending at the head. You may want to examine Floyd's Cycle Detection algorithm. /*This function returns true if given...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT