Related questions
Hi i need an implementation on the LinkListDriver and the LinkListOrdered for this output :
please help me i need this to run
Enter your choice: 1
Enter element: Mary
List Menu Selections
1. add element
2_remove element
3.head element
4. display
5.Exit
Enter your choice: 3
Element @ head: Mary
List Menu Selections
1-add element
2-remove element
3_head element
4.display
5-Exit
Enter your choice:
4
1. Mary
List Menu Selections
1. add element
2. remove element
3.head element
4. display
5. Exit
Enter your choice:
LinkedListDriver
package jsjf;
import java.util.LinkedList;
import java.util.Scanner;
public class LinkedListDriver {
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
LinkedList<String> list = new LinkedList<String>();
int menu = 0;
do {
System.out.println("\nList menu selection\n1.Add element\n2.Remove element\n3.Head\n4.Display\n5.Exit");
System.out.println();
System.out.print("Enter your choice: ");
menu = Integer.parseInt(input.next());
switch (menu) {
case 1:
System.out.print("Enter Element: ");
String Element = input.next();
break;
case 2:
System.out.print("Enter Element: ");
Element = input.next();
break;
case 3:
System.out.print("Enter Element: ");
Element = input.next();
break;
case 4:
System.out.print("Enter Element: ");
Element = input.next();
break;
}
} while (menu != 5); // iterates until 5 (Exit) is entered
input.close();
}
}
Linear Node
package jsjf;
public class LinearNode<E>
{
private LinearNode<E> next;
private E element;
/**
* Creates an empty node.
*/
public LinearNode()
{
next = null;
element = null;
}
public LinearNode(E elem)
{
next = null;
element = elem;
}
public LinearNode<E> getNext()
{
return next;
}
/**
* Sets the node that follows this one.
public void setNext(LinearNode<E> node)
{
next = node;
}
/**
* Returns the element stored in this node.
*
* @return the element stored in this node
*/
public E getElement()
{
return element;
}
/**
* Sets the element stored in this node.
*
* @param elem the element to be stored in this node
*/
public void setElement(E elem)
{
element = elem;
}
}
LinkedOrderedList
package jsjf;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;
import jsjf.exceptions.*;
public class LinkedOrderedList<T> extends LinkedList<T>
implements OrderedListADT<T>
{
public LinkedOrderedList()
{
super();
}
public void add(T element, LinearNode<T> tail)
{
if (!(element instanceof Comparable))
{
throw new NonComparableElementException("LinkedOrderedList");
}
else
{
Comparable<T> comparableElement = (Comparable<T>)element;
LinearNode<T> head = null;
LinearNode<T> current = head;
LinearNode<T> previous = null;
LinearNode<T> newNode = new LinearNode<T>(element);
boolean found = false;
if (isEmpty()) // list is empty
{
head = newNode;
tail = newNode;
}
else if (comparableElement.compareTo(head.getElement()) <= 0)// element goes in front
{
newNode.setNext(head);
head = newNode;
}
else if (comparableElement.compareTo(tail.getElement()) >= 0)// element goes at tail
{
tail.setNext(newNode);
tail = newNode;
}
else // element goes in the middle
{
while ((comparableElement.compareTo(current.getElement()) > 0))
{
previous = current;
current = current.getNext();
}
newNode.setNext(current);
previous.setNext(newNode);
}
int count = 0;
count++;
int modCount = 0;
modCount++;
}
}
@Override
public T removeFirst() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public T removeLast() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public T remove(T element) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public T first() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public T last() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean contains(T target) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean isEmpty() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public int size() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Iterator<T> iterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void forEach(Consumer<? super T> action) {
OrderedListADT.super.forEach(action); //To change body of generated methods, choose Tools | Templates.
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- I'm working on an assignment and i'm trying to create a to-do list in AndroidStudio. I've created the listview, edit text, switch and button, but I've hit a snag with the following: Create a new Java object to hold each todo item, it should contain a string with the text of the todo, and a boolean for if it is urgent or not. Create a List to hold all your items, and for the adapter to use for displaying them. When you click "Add", you should create a new todo item and add it to the list, clear out the text in the EditText, and call "notifyDatasetChanged()" on your adapter so it refreshes. Implement a BaseAdapter to power the ListView. In AndroidStudio, type ctrl + O (the letter ‘O’, not number zero). From the list of inherited functions, implement these ones: int getCount() - This returns the number of rows that will be in your listView. In your case, it should be the number of strings in the array list object ( return list.size() ). Object getItem(int position) – This...arrow_forwardYou may have found it somewhat tedious and unpleasant to use the debugger and visualizer to verify the correctness of your addFirst and addLast methods. There is also the problem that such manual verification becomes stale as soon as you change your code. Imagine that you made some minor but uncertain change to addLast]. To verify that you didn't break anything you'd have to go back and do that whole process again. Yuck. What we really want are some automated tests. But unfortunately there's no easy way to verify correctness of addFirst and addLast] if those are the only two methods we've implemented. That is, there's currently no way to iterate over our list and get bad its values and see that they are correct. That's where the toList method comes in. When called, this method returns a List representation of the Deque. For example, if the Deque has had addLast (5) addLast (9) addLast (10), then addFirst (3) called on it, then the result of toList() should be a List with 3 at the...arrow_forwardFor any element in keysList with a value smaller than 40, print the corresponding value in itemsList, followed by a comma (no spaces). Ex: If keysList = {32, 105, 101, 35} and itemsList = {10, 20, 30, 40}, print: 10,40, #include <iostream>#include <string.h>using namespace std; int main() { const int SIZE_LIST = 4; int keysList[SIZE_LIST]; int itemsList[SIZE_LIST]; int i; cin >> keysList[0]; cin >> keysList[1]; cin >> keysList[2]; cin >> keysList[3]; cin >> itemsList[0]; cin >> itemsList[1]; cin >> itemsList[2]; cin >> itemsList[3]; /* Your code goes here */ cout << endl; return 0;}arrow_forward
- Write a code to the following image using Console.WriteLine.arrow_forwardvb.net lstBox1 contains a list of integers. Write a For Loop to display only the odd integers from lstBox1 in listBox2....arrow_forwardHow does the map react when a new entry is added with an already existing key?arrow_forward
- Java Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node.arrow_forward3.)Declare variables a. The images variable containing an HTML collection of all elements with the tag name "img". b. The photoBucket variable referencing the element with the id "photo_bucket". c. The photoList variable referencing the element with the id "photo_list". 4.) Create a for loop that iterates through all of the items in the images collection. 5.) Within the for loop insert an onclick event handler that runs an anonymous function when an image is clicked. 6.) When an image is clicked it is either moved from the photo bucket to the photo list or from the photo list back to the photo bucket. To determine which action to perform, add the following if else statement to the anonymous function: a. If the parent element of the clicked image has an id equal to "photo_bucket" then do the following: (i) Create an element node named newltem for the li element, (ii) append newltem to the photoList object, and (i) append the image to the newltem object using the appendChild() method....arrow_forwardIn Kotlin, 4.Create a list of Ints from 1 to 25 Use map() with the list and your area function to create a list of the areas of circles with each of the Ints as radiusarrow_forward
- in this android app package com.example.myapplication;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.widget.ListView;public class PlayerActivity2 extends AppCompatActivity {ListView simpleList;String SerialNo[] = {"1", "2", "3", "4", "5", "6","7","8","9","10"};int flags[] = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6, R.drawable.image7, R.drawable.image8, R.drawable.image9, R.drawable.image10};String Names[] = {"mmm", "nnn", "aaa.", "bbb", "ccc", "ddd","eee jk"," ijk","Virgil jk","gil jklk"};String Score[] = {"1", "2","3", "5", "4", "3","5","5","5","5"};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity2);simpleList = (ListView)findViewById(R.id.simpleListView);//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.activity_listview, R.id.textView,...arrow_forwardI am attempting to write a code that will allow me to loop through a series of FITS fies in a folder on my Desktop. This is what I have so far, but no plot as yet. I have included a picture of what the plot should look like after the looping process. import numpy as npimport matplotlib.pyplot as pltimport globfrom astropy.io import fitsfrom astropy.wcs import WCSfrom pathlib import Path%matplotlib inline%matplotlib widget plt.figure(figsize=(5,5))legends = [] def plot_fits_file(file_path): # used this data to test ---------- # lam = np.random.random(100) # flux = np.random.random(100) # -------------------- # below code will work when you have file # all the plot will be on single chart hdul = fits.open(file_path) data = hdul[1].data h1 = hdul[1].header flux = data[1] w = WCS(h1, naxis=1, relax=False, fix=False) lam = w.wcs_pix2world(np.arange(len(flux)), 0)[0] plt.plot(lam, flux) plt.ylim(0, ) plt.xlabel('RV[km/s]')...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education