In this assignment you are to utilize the Node data structure provided on Blackboard.
In this assignment you are to write a main program that implements two methods and a main
method as their driver. So, only main and two methods with it.
Note: You may not use any of the LinkedList class provided on Blackboard, you may use the methods in
it as a guide (you should actually look at them) but you cannot use any of the methods in your
solution. Also, you may not modify the Node class in any way, we will assume that you just used
it as is. You should not submit it. So, assume the linked list class does not exist.
You only need to submit only your drive program.
Implementation Details:
^^^^^^^^^^^^^^^^^^^^^^^
The following are the implementation details of this assignment, you must adhere to all of the
requirements.
Method 1:
^^^^^^^^^
Parameters and return type:
Takes as parameters an array of integers, the size of the array of integer (.length is acceptable also)
and it should return a Node that is supposed to represent the head of a linked list.
Note: You may also choose to make it a void method and pass the head of the linked list as a parameter,
if that's easier for you. You have the choice here.
Method Logic:
The method is supposed to create a linked list represented by its head and populate it with the
numbers stored in the array by placing the even numbers in the array first, followed by the odd
numbers. You may not change the order of the numbers inside of the array, the order must remain
the same as it was read from input.
Example: Assume the array is: [0,1, 4, 6, 7, 9, 2, 10, 11, 14, 13, 19, 20]
The linked list should be 20->14->10->2->6->4->0->1->7->9->11-13->19
So return back from the function the head of this linked list.
Method 2:
^^^^^^^^^
Parameters and return type:
This method should take as a parameter the linked list generated in method 1 represented by
its head.
Method logic:
The method should start by reading in one integer from standard input, and based on that
integer, it needs to shift the linked list by that many positions. Keep in mind that you need
to do the necessary error checking, the shifting can be between 0 and the size of the linked list - 1.
Example:
Assume the given linked list is: 20->14->10->2->6->4->0->1->7->9->11-13->19
You read in an integer: You input the number 3.
The linked list should look like: 2->6->4->0->1->7->9->11-13->19->20->14->10
If you read in a 6:
The linked list should look like: 0->1->7->9->11-13->19->20->14->10->2->6->4
If you read in a 13 The method should print an error asking you to enter a number between 0-12.
The main program:
^^^^^^^^^^^^^^^^^
1. Your program should run and ask the user to input the size of an array of integers. Once that's
done, the program should read these integers and store them into an array.
2. Once the array has been populated and its size is known, then you need to call method 1 defined
above. The result should be a head pointer of a linked list.
At this point you declare a cursor method and go through the linked list and print it to the screen.
Based on the above example: 20 14 10 2 6 4 0 1 7 9 11 13 19.
3. Call method 2
4. Print the linked list resulting from calling method 2. The rotated linked list.
// Node of any Reference type T
public class Node<T>
{
private T value; // this is the data value
private Node<T> next; // this is pointing to the next node
// the node constructor
public Node (T v, Node<T> n)
{
value = v;
next = n;
}
// getters and setters for the node's value and next pointer
public T getValue() {return value;}
public Node<T> getNext() {return next;}
public void setValue(T v){value = v;}
public void setNext(Node<T> n){next = n;}
}
Implement in java please
//make node class with generic value
class Node<T> {
//define left and right node
private Node<T> left;
private Node<T> right;
private T value;
Node(T v){ //Constructor to initialize the values
this.value=v;
}
//getter setters method
public void setValue(T t){
this.value=t;
}
public T getValue(){
return value;
}
public void setLeft(Node<T> t){
this.left=t;
}
public Node<T> getLeft(){
return left;
}
public void setRight(Node<T> t){
this.right=t;
}
public Node<T> getRight(){
return right;
}
}
public class Tester1<T>{
Node<T> root;
public void preorder(Node<T> root){ //function to test node class , this pre-order travarsal
if(root==null)
return;
System.out.print(root.getValue()+" ");
preorder(root.getLeft());
preorder(root.getRight());
}
public static void main(String args[]){ //test with Integer values
Tester1<Integer> t=new Tester1<Integer>();
Node<Integer> root=new Node<>(6);
root.setLeft(new Node<Integer>(7));
root.setRight(new Node<Integer>(8));
t.preorder(root);
}
}
output
6 7 8
In this assignment you are to utilize the Node data structure provided on Blackboard. In this...
In this assignment you are to utilize the Node data structure provided on Blackboard. In this assignmet you are to write a main program that implements two methods and a main method as their driver. So, only main and two methods with it. Note: You may not use any of the LinkedList class provided on Blackboard, you may use the methods in it as a guide (you should actually look at them) but you cannot use any of the methods...
Here is the IntegerLinkedList_incomplete
class:
public class IntegerLinkedList {
static class Node {
/** The element stored at this node */
private int element; // reference to the element stored at this node
/** A reference to the subsequent node in the list */
private Node next; // reference to the subsequent node in the list
/**
* Creates a node with the given element and next node.
*
* @param e the element to be stored
* @param n...
(9 marks) Complete the following methods in the class MyLinkedList based the description provided. b. on i. (3 marks) size() return the number of items in the list. i. (3 marks) count Positives (): return the number of positive values in the list ii. (3 marks) (Advanced) reverse the order of the items in reverse ( the list. If the list is 10 90, then after calling the - 70 - 20 -> method, it should become 90 - 70...
Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...
// 1. Add methods to get and set, Data and Link. Data should be any Comparable object. class Node { Integer data; // Integer is Comparable Node link; public Node(Integer data, Node link) { this.data = data; this.link = link; } public Integer getData() { return data; } public void setData(Integer data) { this.data = data; } public Node getLink() { return link; } public void setLink(Node link) { this.link = link; } } // b. Create MyLinkedList class and...
Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the beginning(root) of the linked list. 2. A removeFromBeginning() function, that removes the node from the beginning of the linked list and assigns the next element as the new beginning(root). 3. A traverse function, that iterates the list and prints the elements in the linked list. For the insertAtBeginning(Node newNode) function: 1. Check if the root is null. If it is, just assign the new...
Java language
Any use of java.util.LinkedList is prohibited
Objective: The goal of this assignment is to practice recursion. ignment: The assignment requires writing recursive methods for some linked list operations. The use of loops in the recursive methods is strictly prohibited in this assignment. That is, you cannot use for, while, and do-while in the recursive methods you will write. You can only use a loop when you will initiate values for a linked list in the main method. You...
starter code
To write a program using the starter code which is
TestLinkedList to see if the LinkedList program has bugs. It will
produce ether a pass or fail.More information is in the first two
pictures.
LinkedList.java
/**
* @author someone
*
* Implements a double-linked list with four errors
*/
public class LinkedList<E>
{
// The first and last nodes in the list
private Node<E> head, tail;
// Number of items stored in the list
private int size;
//...
Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...
Data Structures - Singly Linked Lists You will add a method swapNodes to SinglyLinkedList class (below). This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same node, etc. Write the main method to test the swapNodes method. You may need to traverse the list. package linkedlists; public class SinglyLinkedList<E> implements Cloneable { // ---------------- nested Node class...