In JAVA, please.
THANK YOU
In this project you will create a generic linked list using Java Generics. Description: Create a generic class called GenLinkedList. GenLinkedList will use nodes that store a value of the generic type to store its contents. It should have the following methods. The methods should all operate on the object making the call (none are static). Perform checking of the parameters and throw exceptions where appropriate. The linked list should be singly-linked. It should not use sentinel nodes (empty header and tail nodes). You should strive for an efficient implementation of each method.
g. swap
receives two index positions as parameters, and swaps the nodes at
these positions, provided both positions are within the current size
h. shift
receives an integer as a parameter, and shifts the list forward or
backward this number of nodes, provided it is within the current size
k. insertList
receives a generic List (a Java List) and an index position as parameters,
and copies each value of the passed list into the current list starting
at the index position, provided the index position does not exceed the size.
For example, if list has a,b,c and another list having 1,2,3 is inserted at
position 2, the list becomes a,b,1,2,3,c
i. removeMatching
receives a value of the generic type as a parameter and removes all
occurrences of this value from the list.HI, Please find the solution and upvote the answer.
public class Node<X> {
private X value;
public Node<X> next;
@Override
public String toString() {
return "Node{" +
"value=" + value +
'}';
}
public void setNext(Node<X> next) {
this.next = next;
}
public X getValue() {
return value;
}
public void setValue(X value) {
this.value = value;
}
public Node(X val) {
this.value = val;
next = null;
}
}
import java.util.Collections;
import java.util.List;
public class LinkedList<T> {
private Node<T> head;
public void printAll(){
Node<T> temp= head;
while(temp!=null){
System.out.print(temp+", ");
temp = temp.next;
}
System.out.println();
}
public int size(){
int count = 0;
Node<T> temp= head;
while(temp!=null){
temp=temp.next;
count++;
}
return count;
}
void swap(int index1,int index2){
int size = size();
if(!(index1>=0 && index1< size && index2>=0 && index2< size)){
return;//if indexes are not proper
}
Node<T> temp,temp1 = null,temp2=null;
temp = head;
for (int i = 0; i < size(); i++) {
if(i==index1){
temp1 = temp;
}if(i==index2){
temp2 = temp;
}
temp = temp.next;
}
T val = temp1.getValue();
temp1.setValue(temp2.getValue());
temp2.setValue(val);
}
void shift(int index){
if(index<0 || index>size()){
return;
}
for (int i = index; i < size(); i++) {
Node<T> del = delete(i);
addBeginning(del);
}
}
void insertList(List<T> list, int index){
int k=0;
int size = size();
Collections.reverse(list);
for (int i = index; i < size && k<list.size(); i++) {
insert(new Node<T>(list.get(k++)),index);
}
}
void addBeginning(Node<T> node){
if(node!=null) {
node.next = head;
head = node;
}
}
void add(Node<T> node){
node.next=null;
if(head==null){
head=node;
return;
}
Node<T> temp = head;
while(temp.next!=null){
temp = temp.next;
}
temp.next = node;
}
void removeMatching(Node<T> remove){
Node<T> temp = head;
int i=0;
LinkedList<Integer> ints = new LinkedList<>();
while(temp!=null){//this loop adds all occurrences
if(temp.getValue().equals(remove.getValue())){
ints.add(new Node<>(i));
}
temp = temp.next;//moving pointers
i++;
}
for (int j = 0; j < ints.size(); j++) {//this loop deletes them
delete(ints.get(j).getValue());
}
}
Node<T> get(int index){
if(head==null){
return null;
}
Node temp = head;
int i=0;
while(temp.next!=null && index!=i++){
temp=temp.next;
}
if(i-1==index || i==index ){
return new Node(temp.getValue());
}
else
return null;//index not present
}
Node<T> delete(int index){
if(index==0){
Node<T> temp = head;
head = head.next;
temp.next = null;
return temp;
}
Node<T> temp = head;
Node<T> tempNext = head.next;
int i=1;
while(tempNext!=null && i++!=index){
temp = temp.next;
tempNext = tempNext.next;
}
temp.next = tempNext.next;//temp is pointing to index-1 node
tempNext.next = null;
return tempNext;
}
void set(Node<T> value,int index){
value.next=null;
value.next=null;
if(head==null){
head = value;
head.next=null;
return;
}
if(index==0){
head.setValue(value.getValue());
return;
}
Node temp = head;
int i=0;
while(temp.next!=null && index!=i++){
temp=temp.next;
}
if(head!=temp && index!=0)
temp.setValue(value.getValue());
}
void insert(Node<T> value,int index){
value.next=null;
if(head==null){
head = value;
head.next=null;
return;
}
if(index==0){
value.next=head;
head=value;
}
Node<T> temp = head;
Node<T> tempNext = head.next;
int i=0;
while(tempNext!=null && index!=i++){
temp=temp.next;
tempNext = tempNext.next;
}
value.next = temp.next;
temp.next=value;
}
}
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Node<Character> a = new Node<>('a');
Node<Character> b = new Node<>('b');
Node<Character> c = new Node<>('c');
Node<Character> d = new Node<>('d');
Node<Character> e = new Node<>('e');
Node<Character> f = new Node<>('f');
Node<Character> one = new Node<>('1');
Node<Character> two = new Node<>('2');
Node<Character> three = new Node<>('3');
Node<Character> four = new Node<>('4');
Node<Character> five = new Node<>('5');
LinkedList<Character> list = new LinkedList<>();
list.add(a);
list.add(b);
list.add(c);
list.add(d);
list.add(e);
list.add(f);
System.out.println("List after adding");
list.printAll();
System.out.println();
System.out.println("List after swap 0 with 5");
list.swap(0,5);
list.printAll();
System.out.println();
System.out.println("List after shifting 4");
list.shift(4);
list.printAll();
System.out.println();
System.out.println("List after inserting another list");
list.insertList(Arrays.asList('t','u','v'),3);
list.printAll();
System.out.println("After removing node 't'");
list.removeMatching(new Node<Character>('t'));
list.printAll();;
}
}
Some variables are unused.Feel free to use them in Main.java..
Sample output:

In JAVA, please. THANK YOU In this project you will create a generic linked list using...
Generic Linked Lists ( Program should be written in Java language). Modify the linked list class presented in this chapter so it works with generic types. Add the following methods drawn from the java.util.List interface: -void clear(): remove all elements from the list. -E get(int index): return the element at position index in the list. -E set(int index, E element): replace the element at the specified position with the specified element and return the previous element. Test your generic linked...
C# is the language Create a generic class called “LinkedList” and implement the singly linked list. Implement the following functions: - In C# Function Name Function Parameters Description Empty - Return true if empty else return false. Size - Return the current size of the list. Insert Value Insert the Value at the end of the list. Insert Index, Value Insert the Value at the specified Index. If the Index is out of range then insert the Value at the...
I need help Writing a Python code!!! Implement an ordered list using doubly linked list Implement the following operations for an ordered list of integers ordered in ascending order using a doubly linked list. The “head” of the list be where the “smallest items are and let “tail” be where the largest items are. You may use whatever mechanism you like to keep track of the head and tail of the list. E.g. references or sentinel nodes. • OrderedList ()...
Write a Java program to work with a generic list ADT using a fixed size array, not ArrayList. Create the interface ListInterface with the following methods a) add(newEntry): Adds a new entry to the end of the list. b) add(newPosition, newEntry): Adds a new entry to the list at a given position. c) remove(givenPosition): Removes the entry at a given position from the list. d) clear( ): Removes all entries from the list . e) replace(givenPosition, newEntry): Replaces the entry...
Linked List in Java The data node should be modeled somewhat like this: class node{ int node iNum; node next; } Write a program that creates a linked list and loads it with the numbers 0 to 9. Start with an empty list and then use a "for loop" to fill it. Create a linked list class, a node class, etc. Routines like makeNode and findTail should be methods in the linked list class. Create a showList function to display...
In Java implement a class called Polynomials: This class should store the polynomial using a linked list with nodes. (do not use existing list classes in Java). This class should store only terms with non-zero coefficients. This class should store the polynomial terms in decreasing order of their powers. This class should have a constructor with no parameters that creates a polynomial with no terms, i.e. the polynomial 0. This class should have another constructor that takes a polynomial as...
Need the answers to these RECURSIVE practice problems using
Linked Lists in JAVA . Thank you.
Complete the Link class by writing methods described below. Do not use loops, or create any more methods (other than those specified), class or instance variables. public class Link private Link next; /null if this is the last link private int value; public Link(Link n, int v) nextn valuev; Do not use loops, or create any more methods (other than those specified), class or...
Using an appropriate definition of ListNode, design a simple linked list class called StringList with the following member functions: void add (std::string); int positionOf (std::string); bool setNodeVal(int, std::string); std::vector<std::string> getAsVector(); a default constructor a copy constructor a destructor The add() function adds a new node containing the value of the parameter to the end of the list. The positionOf() function returns the (zero-based) position in the list for the first occurrence of the parameter in the list, or -1 if...
please help!!!! JAVA
I done the project expect one part but I still give you all the
detail that you needed...
and I will post my code please help me fix the
CreateGrid() part in main and make GUI works
List Type Data Structures
Overview :
You will be implementing my version of a linked list. This is a
linked list which has possible sublists descending from each node.
These sublists are used to group together all nodes which...
Doubly Linked List Java Help Details: First, read the DoublyLinkedList.java code and try to understand what each field stores and what each method is doing. Modify and complete the class as described below •The field size was defined in the class but was never maintained. Set the current default value and modify it whenever it is needed in the existing methods and other methods you implement as it is needed. It should always include the number of Nodes inside the...