public class Stack<T> implements StackInterface<T>{
private LinkListNode<T> stkTop;
public Stack() {
stkTop=null;
}
@Override
public T top() throws StackUnderflowException {
if(stkTop == null)
throw new StackUnderflowException();
return stkTop.getInfo();
}
@Override
public void pop() throws StackUnderflowException {
if(stkTop == null)
throw new StackUnderflowException();
LinkListNode<T> temp = stkTop;
stkTop = stkTop.getLink();
temp.setInfo(null);
temp.setLink(null);
}
@Override
public void push(T element) {
LinkListNode<T> newNode = new LinkListNode<T>(element);
if(stkTop == null){
stkTop = newNode;
}
else{
newNode.setLink(stkTop);
stkTop = newNode;
}
}
public String toString(){
String str="";
LinkListNode<T> temp = stkTop;
while(temp != null){
str=temp.getInfo().toString()+" "+str;
temp =temp.getLink();
}
return str;
}
}
=================================================
public class LinkListNode<T> {
private T info;
private LinkListNode<T> link;
public LinkListNode(T info) {
super();
this.info = info;
this.link = null;
}
public T getInfo() {
return info;
}
public void setInfo(T info) {
this.info = info;
}
public LinkListNode<T> getLink() {
return link;
}
public void setLink(LinkListNode<T> link) {
this.link = link;
}
}
========================================================
public interface StackInterface<T> {
T top() throws StackUnderflowException;
void pop() throws StackUnderflowException;
void push(T element);
}
=======================================
public class StackUnderflowException extends Exception {
}
===================================================
public class Main {
public static void main(String[] args) throws StackUnderflowException {
Stack<String> stk = new Stack<>();
stk.push("one");
stk.push("two");
stk.push("three");
stk.push("four");
stk.push("five");
System.out.println("Stack : [ "+stk+" ]");
System.out.println("Top : [ "+(String)stk.top()+" ]");
stk.pop();
System.out.println("After pop : ");
System.out.println(stk);
}
}
======================================================
![@ Javadoc島Declaration Console X 굴좀 Diagrams td> Main (5) Java Application] C:AProgram FilesJavajre1.8.0_161\binjavaw.exe Stac](http://img.homeworklib.com/questions/582ccd20-a62f-11eb-b54d-037951919e58.png?x-oss-process=image/resize,w_560)
Use the following implementation of LinkedListNode to write the Stack4T> classi public class LinkListNodecT>T private T...
public class CharNode{ private CharNode link; private char info; public CharNode(char info) { this.info = info; this.link = null; } public CharNode(char c, CharNode link) { this.info = info; this.link = link; } public CharNode getLink() { return link; } public void setLink(CharNode link) { this.link = link; } public char getInfo() { return info; } public void setInfo(char info) { this.info = info; } } //Remember Queue is a first-in-first-out data structure public class CharQueue { // front is...
Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...
Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T) Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: setInfo Access modifier: public Parameters: info (data type T) Return type: void Task: sets the...
Implement the Unsorted, sorted and indexed lists using Linked List base structure. (LLNode class under support package) Files required: 1. ListInterface.java (given) 2. LLUnsortedList.java (implements ListInterface.java) 3. LLSortedList.java (extends LLUnsortedList.java, implements ListInterface.java) 4. LLIndexedList.java (implements LLIndexedListInterface.java, extends LLUnsortedList.java) 5. Driver ** Maybe create LLIndexedListInterface.java file too even though it is not required file! I need the bolded Java Files (5) to be written separate classes please! The interfaces can be implemented from below! Thank you zip all your files and submit....
Write a recursive method remove(int target, LLNode list) that removes all occurrences of target from list and returns a reference to the new list. For our example list the statement values = remove(6, values); would result in values referencing the list containing 3 9 12 15 18 19 19 and 20. If target is not contained in list then the list remains unchanged. Please also add a driver class to demonstrate that the method is working correctly. LLNode.java //---------------------------------------------------------------------------- //...
In Java:
Assume the "ferrets" variable points to a linked list of
"LLNode." Write code that traverses the list and prints the
following. Do not forget to consider the case where the list is
empty.
The
"LLNode" class is given:
public class LLNode
{
protected T info;
protected LLNode link;
public LLNode(T info)
{
this.info = info;
link = null;
}
public void setInfo(T info)
{
this.info = info;
}
public T getInfo()
{
return info;
}
public void setLink(LLNode...
use
intellij idea
main java
Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: Queue Node<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name:...
Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data...
Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data...
Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: Queue Node<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier:...