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

Create a linked list implementation of a Set class that contains a unique collec

ID: 3841850 • Letter: C

Question

Create a linked list implementation of a Set class that contains a unique collection of objects. More formally, a set contains no pair of elements el and e2 such that e1 middot equals (e2) -= true, and at most one null element. The set class should have the following methods. Set () --Create an empty set void add(Item item) --Add an item if the item does not exist in the set. If the item already exists, do nothing. Boolean remove (Item item)--Remove an item from the set. Return true if the item was removed and false if the item did not exist in the set. Boolean is Empty ()--Is the set empty? Return true or false. Int size () --Return the number of items in the Set. Use a singly linked list. Create an inner class Node that contains the fields item and next to support your Set class.

Explanation / Answer

Hello, I am Trying to solve question in Java.

void add(int pos, element obj) - is syntax of SET Interface type and of LinkedList Class. It means element obj is inserted into linklist at specific position.

boolean add(element obj) - returns true if element element added.

boolean remove(int pos) - removes an element from particular position.

boolean IsEmpty() - checks whether function returns true if it contains +ve element else false.

set() - this method replaces element at specified position in list with specified element.

int size - returns number of elements in linklist.

*******A program showing all related things in question********

public class set

{

public class node // inner class

{

  LinkList<string> LLObj = new LinkList<string>;

public void items() // Containing Two Methods

{

LLObj.add("America")

LLObj.add("India");

LLObj.add("Australia");

LLObj.add("England");

}

public void next() // 2nd method of inner class

{

string ex = "China" ;

LLObj.add(2,"Japan");

System.out,println("First Element"+LLObj.getFirst());

System.out,println("First Element"+LLObj.getLast());

LLObj.set(3,"Malaysia");

}

}

// In Outer class

public void Display_Inner()

{

node n = new node();

n.items();

n.next();

}

}

public class Main_Function

{

public static void mian(String args[])

{

set s = new set();

s.Display_inner();

}

}

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