SlideShare a Scribd company logo
1 of 8
Java Foundations
StackADT.java
/**
* Defines the interface to a stack collection.
*
* @author Java Foundations
* @version 4.0
*/
public interface StackADT<T> {
/**
* Adds the specified element to the top of this stack.
*
* @param element element to be pushed onto the stack
*/
public void push(T element);
/**
* Removes and returns the top element from this stack.
*
* @return the element removed from the stack
* @throws EmptyCollectionException if the stack is empty
*/
public T pop();
/**
* Returns the top element of this stack without removing it from the stack.
*
* @return the element on top of the stack. It is not removed from the stack
* @throws EmptyCollectionException if the stack is empty
*/
public T peek();
/**
* Returns true if this stack contains no elements.
*
* @return true if the stack is empty, false if the stack is not empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this stack.
*
* @return the number of elements in the stack
*/
public int size();
}
QueueADT.java
/**
* QueueADT defines the interface to a queue collection.
*
* @author Java Foundation
* @version 4.0
*/
public interface QueueADT<T> {
/**
* Adds one element to the rear of this queue.
*
* @param element the element to be added to the rear of the queue
*/
public void enqueue(T element);
/**
* Removes and returns the element at the front of this queue.
*
* @return the element at the front of the queue
* @throws EmptyCollectionException if the queue is empty
*/
public T dequeue();
/**
* Returns without removing the element at the front of this queue.
*
* @return the first element in the queue
* @throws EmptyCollectionException if the queue is empty
*/
public T first();
/**
* Returns true if this queue contains no elements.
*
* @return true if the queue is empty, false if the queue is not empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this queue.
*
* @return the number of elements in the queue
*/
public int size();
}
LinkedDeque.java
public class LinkedDeque<T> implements QueueADT<T>, StackADT<T>, DequeADT<T> {
// inner class for a double linked list node
private class DNode<T> {
private T element;
private DNode<T> prev, next;
}
// data fields for the LinkedDeque class
private DNode<T> front, rear;
private int size;
// deque interface methods
@Override
public void addFirst(T element) {
// create a new node and set it up
DNode<T> newNode = new DNode<T>();
newNode.element = element; // from param to new node obj
newNode.prev = newNode.next = null;
if(this.isEmpty()) {
// we are making the only node in the deque
this.rear = this.front = newNode;
} else {
// there already exists a new node
// so, put the new node before the front node
newNode.next = this.front;
this.front.prev = newNode;
this.front = newNode;
}
this.size++;
}
@Override
public T removeFirst() {
T grabbedElt = this.getFirst(); // checks for empty for us
if(this.size() == 1) {
// we are removing the only node
// so the deque is becoming empty
} else {
// there are multiple nodes in the queue
// so the rear won't change and we just mess with front end
}
this.size--;
return grabbedElt;
}
@Override
public T getFirst() {
if(this.isEmpty()) {
throw new EmptyCollectionException("LinkedDeque");
}
return this.front.element;
}
@Override
public void addLast(T element) {
}
@Override
public T removeLast() {
return null;
}
@Override
public T getLast() {
if(this.isEmpty()) {
throw new EmptyCollectionException("LinkedDeque");
}
return this.rear.element;
}
// stack interface methods
@Override
public void push(T element) {
this.addFirst(element);
}
@Override
public T pop() {
return this.removeFirst();
}
@Override
public T peek() {
return this.getFirst();
}
// queue interface methods
@Override
public void enqueue(T element) {
// TODO Auto-generated method stub
}
@Override
public T dequeue() {
// TODO Auto-generated method stub
return null;
}
@Override
public T first() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isEmpty() {
return (this.size == 0);
}
@Override
public int size() {
return this.size;
}
@Override
public String toString() {
String s = "LinkedDeque of size" + this.size() + "containing (front to back)";
for (DNode <T> curr = this.front; curr != null; curr = curr.next) {
s = s + curr.element;
if(curr.next != null) {
s = s + ", ";
} else {
s = s + ".";
}
}
}
}
EmptyCollectionException.java
/**
* Represents the situation in which a collection is empty.
*
* @author Java Foundations
* @version 4.0
*/
public class EmptyCollectionException extends RuntimeException
{
/**
* Sets up this exception with an appropriate message.
* @param collection the name of the collection
*/
public EmptyCollectionException(String collection)
{
super("The " + collection + " is empty.");
}
}
DequeADT.java
public interface DequeADT<T> {
/**
* The DequeADT (double-ended queue) provides methods for inserting, deleting
* and getting either the first or last element of a sequence of elements.
*/
/**
* Adds a new element to the head of this deque.
*
* @param element the element to insert at the head of this deque
*/
public void addFirst(T element);
/**
* Removes and returns the head element of this deque.
*
* @return the head element of this deque
* @throws EmptyCollectionException if the deque is empty
*/
public T removeFirst();
/**
* @return the head element of this deque
* @throws EmptyCollectionException if the deque is empty
*/
public T getFirst();
/**
* Adds a new element to the tail of this deque.
*
* @param element the element to insert at the tail of this deque
*/
public void addLast(T element);
/**
* Removes and returns the tail element of this deque.
*
* @return the tail element of this deque
* @throws EmptyCollectionException if the deque is empty
*/
public T removeLast();
/**
* @return the tail element of this deque
* @throws EmptyCollectionException if the deque is empty
*/
public T getLast();
/**
* Returns true if this deque contains no elements.
*
* @return true if the deque is empty, false if the deque is not empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this deque.
*
* @return the number of elements in the deque
*/
public int size();
}
have a toString() method that prints the contents of the data structure on one line. Implementing
multiple interfaces enqueue method should invoke addLast and dequeue should removeFirst).
Make sure to implement every method of all three interfaces. The Main Class You need to have a
Main class that performs the following operations. First, test the DequeADT: - Create a
DequeADT variable for subtype 'String' that contains a LinkedDeque object. - Add 10 items to
the front (all items should be unique, hint use letters ' A ', ' B '), then print the sate of the Deque. -
Remove 5 items from the back (and print the state of the Deque) - Add 5 items to the back (and
print the state of the Deque) - Perform a circular right shift 10 times - A circular right shift means
to remove an from the back, then add that same element to the front - Be sure to print out the
state of the Deque after each shift - Perform a circular left shift 10 times - A circular left shift
means to remove an from the front, then add that same element to the back - Be sure to print out
the state of the Deque after each shift - getLast() to print out the last element Then, use a Deque
as a stack using the StackADT: - Make variable of type 'StackADT', and instantiate it with a
LinkedDeque object - push() 5 elements, print out stack - pop() each element and print it out in a
while loop Then, use a Deque as a queue using the QueueADT: - Make variable of type
'QueueADT, and instantiate it with a LinkedDeque object - enqueue() 5 elements, print out
queue - dequeue( ) an element each element and print it out in a while loop

More Related Content

Similar to Java Foundations StackADT-java --- - Defines the interface to a stack.docx

I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfadianantsolutions
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdfankit11134
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfaioils
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdfsyedabdul78662
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfinfo430661
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfsiennatimbok52331
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfbabitasingh698417
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxcgraciela1
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docxBlakeSGMHemmingss
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdffathimafancyjeweller
 
For the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfFor the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfxlynettalampleyxc
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfStewart29UReesa
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manualChandrapriya Jayabal
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfConint29
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxVictorzH8Bondx
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfsauravmanwanicp
 
Hi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfHi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfpritikulkarni20
 

Similar to Java Foundations StackADT-java --- - Defines the interface to a stack.docx (20)

I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdf
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
 
Posfix
PosfixPosfix
Posfix
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
For the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfFor the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdf
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
 
Hi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfHi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdf
 

More from VictorXUQGloverl

Look at situations such as radiological- nuclear accidents- technologi.docx
Look at situations such as radiological- nuclear accidents- technologi.docxLook at situations such as radiological- nuclear accidents- technologi.docx
Look at situations such as radiological- nuclear accidents- technologi.docxVictorXUQGloverl
 
Learning Activity 16-1- Innate Immune Defenses in Different Cases List.docx
Learning Activity 16-1- Innate Immune Defenses in Different Cases List.docxLearning Activity 16-1- Innate Immune Defenses in Different Cases List.docx
Learning Activity 16-1- Innate Immune Defenses in Different Cases List.docxVictorXUQGloverl
 
List and describe the 5 characteristics of epithelial tissues.docx
List and describe the 5 characteristics of epithelial tissues.docxList and describe the 5 characteristics of epithelial tissues.docx
List and describe the 5 characteristics of epithelial tissues.docxVictorXUQGloverl
 
LO32 Identify the differences between transcription and translation LO.docx
LO32 Identify the differences between transcription and translation LO.docxLO32 Identify the differences between transcription and translation LO.docx
LO32 Identify the differences between transcription and translation LO.docxVictorXUQGloverl
 
List + describe the 3 types of skin burns.docx
List + describe the 3 types of skin burns.docxList + describe the 3 types of skin burns.docx
List + describe the 3 types of skin burns.docxVictorXUQGloverl
 
List and describe the modes of secretion + give examples where used.docx
List and describe the modes of secretion + give examples where used.docxList and describe the modes of secretion + give examples where used.docx
List and describe the modes of secretion + give examples where used.docxVictorXUQGloverl
 
lim had to give a presentail- Planning phase Analysis phase Design pha.docx
lim had to give a presentail- Planning phase Analysis phase Design pha.docxlim had to give a presentail- Planning phase Analysis phase Design pha.docx
lim had to give a presentail- Planning phase Analysis phase Design pha.docxVictorXUQGloverl
 
Let- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docx
Let- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docxLet- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docx
Let- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docxVictorXUQGloverl
 
Let Y be a continuous random variable with density fY- where Y might t.docx
Let Y be a continuous random variable with density fY- where Y might t.docxLet Y be a continuous random variable with density fY- where Y might t.docx
Let Y be a continuous random variable with density fY- where Y might t.docxVictorXUQGloverl
 
Let X1- - - - - Xn be a random sample from an uniform distribution U(0.docx
Let X1- - - - - Xn be a random sample from an uniform distribution U(0.docxLet X1- - - - - Xn be a random sample from an uniform distribution U(0.docx
Let X1- - - - - Xn be a random sample from an uniform distribution U(0.docxVictorXUQGloverl
 
Let X be a normal random variable with mean 201 units and standard dev.docx
Let X be a normal random variable with mean 201 units and standard dev.docxLet X be a normal random variable with mean 201 units and standard dev.docx
Let X be a normal random variable with mean 201 units and standard dev.docxVictorXUQGloverl
 
Let f be a maximum flow on a network G from vertex s to vertex t- and.docx
Let f be a maximum flow on a network G from vertex s to vertex t- and.docxLet f be a maximum flow on a network G from vertex s to vertex t- and.docx
Let f be a maximum flow on a network G from vertex s to vertex t- and.docxVictorXUQGloverl
 
Leaving an employee alone as long as they are performing satisfactoril.docx
Leaving an employee alone as long as they are performing satisfactoril.docxLeaving an employee alone as long as they are performing satisfactoril.docx
Leaving an employee alone as long as they are performing satisfactoril.docxVictorXUQGloverl
 
Last question- You conduct the Gram stain on two cultures of a Gram+ o.docx
Last question- You conduct the Gram stain on two cultures of a Gram+ o.docxLast question- You conduct the Gram stain on two cultures of a Gram+ o.docx
Last question- You conduct the Gram stain on two cultures of a Gram+ o.docxVictorXUQGloverl
 
Label- F BB W T Figure 24-1.docx
Label- F BB W T Figure 24-1.docxLabel- F BB W T Figure 24-1.docx
Label- F BB W T Figure 24-1.docxVictorXUQGloverl
 
Lab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docx
Lab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docxLab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docx
Lab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docxVictorXUQGloverl
 
John's boss knows that he has taken purchasing courses at Sault Colleg.docx
John's boss knows that he has taken purchasing courses at Sault Colleg.docxJohn's boss knows that he has taken purchasing courses at Sault Colleg.docx
John's boss knows that he has taken purchasing courses at Sault Colleg.docxVictorXUQGloverl
 
Lab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docx
Lab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docxLab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docx
Lab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docxVictorXUQGloverl
 
Label the following diagram to describe the overall equation of cellul.docx
Label the following diagram to describe the overall equation of cellul.docxLabel the following diagram to describe the overall equation of cellul.docx
Label the following diagram to describe the overall equation of cellul.docxVictorXUQGloverl
 
Lab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docx
Lab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docxLab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docx
Lab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docxVictorXUQGloverl
 

More from VictorXUQGloverl (20)

Look at situations such as radiological- nuclear accidents- technologi.docx
Look at situations such as radiological- nuclear accidents- technologi.docxLook at situations such as radiological- nuclear accidents- technologi.docx
Look at situations such as radiological- nuclear accidents- technologi.docx
 
Learning Activity 16-1- Innate Immune Defenses in Different Cases List.docx
Learning Activity 16-1- Innate Immune Defenses in Different Cases List.docxLearning Activity 16-1- Innate Immune Defenses in Different Cases List.docx
Learning Activity 16-1- Innate Immune Defenses in Different Cases List.docx
 
List and describe the 5 characteristics of epithelial tissues.docx
List and describe the 5 characteristics of epithelial tissues.docxList and describe the 5 characteristics of epithelial tissues.docx
List and describe the 5 characteristics of epithelial tissues.docx
 
LO32 Identify the differences between transcription and translation LO.docx
LO32 Identify the differences between transcription and translation LO.docxLO32 Identify the differences between transcription and translation LO.docx
LO32 Identify the differences between transcription and translation LO.docx
 
List + describe the 3 types of skin burns.docx
List + describe the 3 types of skin burns.docxList + describe the 3 types of skin burns.docx
List + describe the 3 types of skin burns.docx
 
List and describe the modes of secretion + give examples where used.docx
List and describe the modes of secretion + give examples where used.docxList and describe the modes of secretion + give examples where used.docx
List and describe the modes of secretion + give examples where used.docx
 
lim had to give a presentail- Planning phase Analysis phase Design pha.docx
lim had to give a presentail- Planning phase Analysis phase Design pha.docxlim had to give a presentail- Planning phase Analysis phase Design pha.docx
lim had to give a presentail- Planning phase Analysis phase Design pha.docx
 
Let- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docx
Let- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docxLet- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docx
Let- if - the event of cutbres a hat Iet N - the tient of fertre a fec.docx
 
Let Y be a continuous random variable with density fY- where Y might t.docx
Let Y be a continuous random variable with density fY- where Y might t.docxLet Y be a continuous random variable with density fY- where Y might t.docx
Let Y be a continuous random variable with density fY- where Y might t.docx
 
Let X1- - - - - Xn be a random sample from an uniform distribution U(0.docx
Let X1- - - - - Xn be a random sample from an uniform distribution U(0.docxLet X1- - - - - Xn be a random sample from an uniform distribution U(0.docx
Let X1- - - - - Xn be a random sample from an uniform distribution U(0.docx
 
Let X be a normal random variable with mean 201 units and standard dev.docx
Let X be a normal random variable with mean 201 units and standard dev.docxLet X be a normal random variable with mean 201 units and standard dev.docx
Let X be a normal random variable with mean 201 units and standard dev.docx
 
Let f be a maximum flow on a network G from vertex s to vertex t- and.docx
Let f be a maximum flow on a network G from vertex s to vertex t- and.docxLet f be a maximum flow on a network G from vertex s to vertex t- and.docx
Let f be a maximum flow on a network G from vertex s to vertex t- and.docx
 
Leaving an employee alone as long as they are performing satisfactoril.docx
Leaving an employee alone as long as they are performing satisfactoril.docxLeaving an employee alone as long as they are performing satisfactoril.docx
Leaving an employee alone as long as they are performing satisfactoril.docx
 
Last question- You conduct the Gram stain on two cultures of a Gram+ o.docx
Last question- You conduct the Gram stain on two cultures of a Gram+ o.docxLast question- You conduct the Gram stain on two cultures of a Gram+ o.docx
Last question- You conduct the Gram stain on two cultures of a Gram+ o.docx
 
Label- F BB W T Figure 24-1.docx
Label- F BB W T Figure 24-1.docxLabel- F BB W T Figure 24-1.docx
Label- F BB W T Figure 24-1.docx
 
Lab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docx
Lab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docxLab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docx
Lab 4-Protists 8- Two silica valves Traits 9- Lobe-shaped pseudopodia.docx
 
John's boss knows that he has taken purchasing courses at Sault Colleg.docx
John's boss knows that he has taken purchasing courses at Sault Colleg.docxJohn's boss knows that he has taken purchasing courses at Sault Colleg.docx
John's boss knows that he has taken purchasing courses at Sault Colleg.docx
 
Lab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docx
Lab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docxLab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docx
Lab1-3 Step by step algorithm- Assembly implementation fuction- (nuirk.docx
 
Label the following diagram to describe the overall equation of cellul.docx
Label the following diagram to describe the overall equation of cellul.docxLabel the following diagram to describe the overall equation of cellul.docx
Label the following diagram to describe the overall equation of cellul.docx
 
Lab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docx
Lab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docxLab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docx
Lab 4- Protists Traits 8- Two silica valves 9- Lobe shaped preudopodia.docx
 

Recently uploaded

PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 

Recently uploaded (20)

PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 

Java Foundations StackADT-java --- - Defines the interface to a stack.docx

  • 1. Java Foundations StackADT.java /** * Defines the interface to a stack collection. * * @author Java Foundations * @version 4.0 */ public interface StackADT<T> { /** * Adds the specified element to the top of this stack. * * @param element element to be pushed onto the stack */ public void push(T element); /** * Removes and returns the top element from this stack. * * @return the element removed from the stack * @throws EmptyCollectionException if the stack is empty */ public T pop(); /** * Returns the top element of this stack without removing it from the stack. * * @return the element on top of the stack. It is not removed from the stack * @throws EmptyCollectionException if the stack is empty */ public T peek(); /** * Returns true if this stack contains no elements. * * @return true if the stack is empty, false if the stack is not empty */ public boolean isEmpty(); /** * Returns the number of elements in this stack. * * @return the number of elements in the stack
  • 2. */ public int size(); } QueueADT.java /** * QueueADT defines the interface to a queue collection. * * @author Java Foundation * @version 4.0 */ public interface QueueADT<T> { /** * Adds one element to the rear of this queue. * * @param element the element to be added to the rear of the queue */ public void enqueue(T element); /** * Removes and returns the element at the front of this queue. * * @return the element at the front of the queue * @throws EmptyCollectionException if the queue is empty */ public T dequeue(); /** * Returns without removing the element at the front of this queue. * * @return the first element in the queue * @throws EmptyCollectionException if the queue is empty */ public T first(); /** * Returns true if this queue contains no elements. * * @return true if the queue is empty, false if the queue is not empty */ public boolean isEmpty(); /** * Returns the number of elements in this queue. *
  • 3. * @return the number of elements in the queue */ public int size(); } LinkedDeque.java public class LinkedDeque<T> implements QueueADT<T>, StackADT<T>, DequeADT<T> { // inner class for a double linked list node private class DNode<T> { private T element; private DNode<T> prev, next; } // data fields for the LinkedDeque class private DNode<T> front, rear; private int size; // deque interface methods @Override public void addFirst(T element) { // create a new node and set it up DNode<T> newNode = new DNode<T>(); newNode.element = element; // from param to new node obj newNode.prev = newNode.next = null; if(this.isEmpty()) { // we are making the only node in the deque this.rear = this.front = newNode; } else { // there already exists a new node // so, put the new node before the front node newNode.next = this.front; this.front.prev = newNode; this.front = newNode; } this.size++; } @Override public T removeFirst() { T grabbedElt = this.getFirst(); // checks for empty for us
  • 4. if(this.size() == 1) { // we are removing the only node // so the deque is becoming empty } else { // there are multiple nodes in the queue // so the rear won't change and we just mess with front end } this.size--; return grabbedElt; } @Override public T getFirst() { if(this.isEmpty()) { throw new EmptyCollectionException("LinkedDeque"); } return this.front.element; } @Override public void addLast(T element) { } @Override public T removeLast() { return null; } @Override public T getLast() { if(this.isEmpty()) { throw new EmptyCollectionException("LinkedDeque"); } return this.rear.element; } // stack interface methods @Override public void push(T element) {
  • 5. this.addFirst(element); } @Override public T pop() { return this.removeFirst(); } @Override public T peek() { return this.getFirst(); } // queue interface methods @Override public void enqueue(T element) { // TODO Auto-generated method stub } @Override public T dequeue() { // TODO Auto-generated method stub return null; } @Override public T first() { // TODO Auto-generated method stub return null; } @Override public boolean isEmpty() { return (this.size == 0); } @Override public int size() { return this.size; } @Override public String toString() { String s = "LinkedDeque of size" + this.size() + "containing (front to back)";
  • 6. for (DNode <T> curr = this.front; curr != null; curr = curr.next) { s = s + curr.element; if(curr.next != null) { s = s + ", "; } else { s = s + "."; } } } } EmptyCollectionException.java /** * Represents the situation in which a collection is empty. * * @author Java Foundations * @version 4.0 */ public class EmptyCollectionException extends RuntimeException { /** * Sets up this exception with an appropriate message. * @param collection the name of the collection */ public EmptyCollectionException(String collection) { super("The " + collection + " is empty."); } } DequeADT.java public interface DequeADT<T> { /** * The DequeADT (double-ended queue) provides methods for inserting, deleting * and getting either the first or last element of a sequence of elements. */ /** * Adds a new element to the head of this deque. * * @param element the element to insert at the head of this deque */ public void addFirst(T element);
  • 7. /** * Removes and returns the head element of this deque. * * @return the head element of this deque * @throws EmptyCollectionException if the deque is empty */ public T removeFirst(); /** * @return the head element of this deque * @throws EmptyCollectionException if the deque is empty */ public T getFirst(); /** * Adds a new element to the tail of this deque. * * @param element the element to insert at the tail of this deque */ public void addLast(T element); /** * Removes and returns the tail element of this deque. * * @return the tail element of this deque * @throws EmptyCollectionException if the deque is empty */ public T removeLast(); /** * @return the tail element of this deque * @throws EmptyCollectionException if the deque is empty */ public T getLast(); /** * Returns true if this deque contains no elements. * * @return true if the deque is empty, false if the deque is not empty */ public boolean isEmpty(); /** * Returns the number of elements in this deque. * * @return the number of elements in the deque
  • 8. */ public int size(); } have a toString() method that prints the contents of the data structure on one line. Implementing multiple interfaces enqueue method should invoke addLast and dequeue should removeFirst). Make sure to implement every method of all three interfaces. The Main Class You need to have a Main class that performs the following operations. First, test the DequeADT: - Create a DequeADT variable for subtype 'String' that contains a LinkedDeque object. - Add 10 items to the front (all items should be unique, hint use letters ' A ', ' B '), then print the sate of the Deque. - Remove 5 items from the back (and print the state of the Deque) - Add 5 items to the back (and print the state of the Deque) - Perform a circular right shift 10 times - A circular right shift means to remove an from the back, then add that same element to the front - Be sure to print out the state of the Deque after each shift - Perform a circular left shift 10 times - A circular left shift means to remove an from the front, then add that same element to the back - Be sure to print out the state of the Deque after each shift - getLast() to print out the last element Then, use a Deque as a stack using the StackADT: - Make variable of type 'StackADT', and instantiate it with a LinkedDeque object - push() 5 elements, print out stack - pop() each element and print it out in a while loop Then, use a Deque as a queue using the QueueADT: - Make variable of type 'QueueADT, and instantiate it with a LinkedDeque object - enqueue() 5 elements, print out queue - dequeue( ) an element each element and print it out in a while loop