Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Also, how would this be different if Node was used as an implementation instead

ID: 3592056 • Letter: A

Question

Also, how would this be different if Node was used as an implementation instead of Link<T> ?

"Since sets and bags are unordered collections, how is it that we are able to determine whether they contain a particular item?" the Galaxers ask. Since we know the size of the collection, we can traverse the structure to see if the given item is present. In fact, the any data structure. Let me write it for you using a linked structure that makes use of an inner class Link ” public boolean contains (T item)

Explanation / Answer

Below is the implementation of contains method of linked list:

public boolean contains(T item) {

//Getting the head in one temporary Node

Link<T> node = head;

//iterating till node is not null

//or we found the matching node

while(node!=null) {

//comparing the given item with the node's item value

//if same then returning true

if(node.item.equals(item)) {

return true;

}

//if value is not matched then moving to the next node

node = node.next;

}

//if no node is matched then returning false

return false;

}

how would this be different if Node was used as an implementation instead of Link<T> ?

Answer: It will not create any difference as you will always have getter to get the current node's value so then also you can compare with the given item value with the current node's value and then return true otheriwse false.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote