Below the implementation of insertAt() method to the existing LinkedList class.
Copy the below method to your existing LinkedList class. Make minor modifications as per your class functionality and test.
=======================================================================================
@Override
public void insertAt(int index, Object o) throws IllegalAccessException {
Node node = head;
Node prevNode = null;
//Throw IllegalArgumentException if index <0 or > size
if(index <0 || index > size){
throw new IllegalArgumentException("Insertion index out of range");
}else if (index == 0) { // if index = 0 means insertion at first node.
Node newNode = new Node();
newNode.data = o;
newNode.next = head;//current head node pointing to new node next.
head = newNode;// new node set as head node.
size++;
} else {
for (int i = 0; i < size; i++) {
if (i == index) {
Node newNode = new Node();
newNode.data = o;
newNode.next = prevNode.next;//link new node next to prevnode next
prevNode.next = newNode;//link new node to prev node next
size++;
break;
}
prevNode = node;
node = node.next;
}
}
}
=======================================================================================
Problem 1 Enhance the LinkedList class by adding following methods to do some more operations of...
Create a complete LinkedList class which implements all of the methods listed below using dynamic memory allocation. You will need a Node class to represent each node in the list. The list should store String values. Include a main method which tests all the methods of your list. Also answer these questions: What is the time complexity (using big-O notation) of these operations in your linked list? add(String val) add(int index, String val) get(int index) remove(String val) Submit three files:...
In Python 3 Write a LinkedList class that has recursive implementations of the display, remove, contains, insert, and normal_list methods. You may use default arguments and/or helper functions. The file must be named: LinkedList.py Here is what I have for my code so far. The methods I need the recursive implementations for will be bolded: class Node: """ Represents a node in a linked list (parent class) """ def __init__(self, data): self.data = data self.next = None class LinkedList: """...
C++ Implement a class template for a LinkedList.(doubly linked). Also, your class will have a tailPtr in addition to a headPtr along with methods to get, set, insert and remove values at either end of the list. Call these getFirst, getLast, setFirst, setLast, insertFirst, insertLast, removeFirst, removeLast. Don't forget, you also need a copy constructor and destructor plus getLength, isEmpty and clear methods. Overload the stream insertion operator as a friend function which outputs the list in format { 1,...
Create a Java code that includes all the methods from the
Lecture slides following the ADTs
LECTURE SLIDES
Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....
RE-POSTED - Computer Science staff, I need this question
answered. It will determine a pass or a fail. Its very imortant
that this and the other questions posted are answered 100% Thank
you.
13 - Template C++ Advance
Please Only answer assignment if your code is 100%. When
pasteing your code use text so I may copy and paste into visual
studio. The code and questions must be answered 100% correct and
works. Thank you.
Programming Assignment
Convert the int...
I need help with the Implementation of an Ordered List (Template Files) public interface OrderedStructure { public abstract int size(); public abstract boolean add( Comparable obj ) throws IllegalArgumentException; public abstract Object get( int pos ) throws IndexOutOfBoundsException; public abstract void remove( int pos ) throws IndexOutOfBoundsException; public abstract void merge( OrderedList other ); } import java.util.NoSuchElementException; public class OrderedList implements OrderedStructure { // Implementation of the doubly linked nodes (nested-class) private static class Node { private Comparable value; private...
Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...
Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for a list of size N? Group of answer choices O(1) O(log N) O(N) O(N log N) Flag this Question Question 21 pts Java's ArrayList class represents a basic array. As a convenience for the user, when the capacity of the backing array is exceeded, the class handles creating a new larger array and copying over the existing items. Its add(int index, E element) method...
Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...
Modify listlink.java program (non generic) by adding the
following methods:
public void insertsorted(x); // Inert x in a sorted
list.
public void deletex(x); //Search for x in the sorted list,
if found, delete it from the sorted list.
Assume you have a data file p2.txt with the following
contents:
8
4 15 23 12 36 5 36 42
3
5 14 4
and your java program is in xxxxx.java file, where xxxxx is
the first 5 characters of your last...