i i need an implementation on the LinkListDriver and the LinkListOrdered for this output : 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: Linked
i i need an implementation on the LinkListDriver and the LinkListOrdered for this output : 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: Linked
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Hi i need an implementation on the LinkListDriver and the LinkListOrdered for this output :
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 list = new LinkedList();
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
{
private LinearNode next;
private E element;
/**
* Creates an empty node.
*/
public LinearNode()
{
next = null;
element = null;
}
public LinearNode(E elem)
{
next = null;
element = elem;
}
public LinearNode getNext()
{
return next;
}
/**
* Sets the node that follows this one.
public void setNext(LinearNode 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 extends LinkedList
implements OrderedListADT
{
public LinkedOrderedList()
{
super();
}
public void add(T element, LinearNode tail)
{
if (!(element instanceof Comparable))
{
throw new NonComparableElementException("LinkedOrderedList");
}
else
{
Comparable comparableElement = (Comparable)element;
LinearNode head = null;
LinearNode current = head;
LinearNode previous = null;
LinearNode newNode = new LinearNode(element);
boolean found = false;
if (isEmpty()) // list is empty
{
head = newNode;
tail = newNode;
}
else if (comparableElement.compareTo(head.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 iterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void forEach(Consumer action) {
OrderedListADT.super.forEach(action); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Spliterator spliterator() {
return OrderedListADT.super.spliterator(); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void add(T element) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Linked List
//Explanation is added in comments
import java.util.Scanner;
public class LinkedList {
Scanner keyboard = new Scanner(System.in);
//head will represent starting point
Node head; // head to store starting point of list
private class Node
{ // nested class to define nodes
int data;
Node next;
}
public void build(){
System.out.println("Enter number of nodes in the list.\n");
int N=keyboard. nextInt(); // N is number of nodes
LinkedList list=new LinkedList();
for (int i=0;i extends LinkedList
implements OrderedListADT
{
public LinkedOrderedList()
{
super();
}
public void add(T element, LinearNode tail)
{
if (!(element instanceof Comparable))
{
throw new NonComparableElementException("LinkedOrderedList");
}
else
{
Comparable comparableElement = (Comparable)element;
LinearNode head = null;
LinearNode current = head;
LinearNode previous = null;
LinearNode newNode = new LinearNode(element);
boolean found = false;
if (isEmpty()) // list is empty
{
head = newNode;
tail = newNode;
}
else if (comparableElement.compareTo(head.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 iterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void forEach(Consumer action) {
OrderedListADT.super.forEach(action); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Spliterator spliterator() {
return OrderedListADT.super.spliterator(); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void add(T element) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
OrderedListADT.java
package jsjf;
public interface OrderedListADT extends ListADT
{
/**
* Adds the specified element to this list at the proper location
*
* @param element the element to be added to this list
*/
public void add(T element);
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education