
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Linked_List;
import java.util.Scanner;
/**
*
* @author lab1257-15
*/
public class Demo {
public static boolean has42 (RefUnsortedList<Integer> t)
{
t.reset();
for (int i=1; i<=t.size();i++)
if (t.getNext()==42)
return true;
return false;
}
public static void RemoveAll(RefUnsortedList<Integer> t, int v)
{
while(t.contains(v))
{
t.remove(v);
}
}
public static void main(String[] args) {
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Linked_List;
/**
*
* @author lab1257-15
*/
public class LLNode<T>
{
private LLNode<T> link;
private T info;
public LLNode(T info)
{
this.info = info;
link = null;
}
public void setInfo(T info)
// Sets info of this LLNode.
{
this.info = info;
}
public T getInfo()
// Returns info of this LLONode.
{
return info;
}
public void setLink(LLNode<T> link)
// Sets link of this LLNode.
{
this.link = link;
}
public LLNode<T> getLink()
// Returns link of this LLNode.
{
return link;
}
}
package Linkedqueue;
public class LinkedUnbndQueue<T> implements UnboundedQueueInterface<T>
{
protected LLNode<T> front; // reference to the front of this queue
protected LLNode<T> rear; // reference to the rear of this queue
public LinkedUnbndQueue()
{
front = null;
rear = null;
}
public void enqueue(T element)
// Adds element to the rear of this queue.
{
LLNode<T> newNode = new LLNode<T>(element);
if (rear == null)
front = newNode;
else
rear.setLink(newNode);
rear = newNode;
}
public T dequeue()
// Throws QueueUnderflowException if this queue is empty;
// otherwise, removes front element from this queue and returns it.
{
if (isEmpty())
throw new QueueUnderflowException("Dequeue attempted on empty queue.");
else
{
T element;
element = front.getInfo();
front = front.getLink();
if (front == null)
rear = null;
return element;
}
}
public boolean isEmpty()
// Returns true if this queue is empty; otherwise, returns false.
{
if (front == null)
return true;
else
return false;
}
}
package Linkeded;
public class LinkedStack<T> implements UnboundedStackInterface<T>
{
LLNode<T> top; // reference to the top of this stack
public LinkedStack()
{
top = null;
}
public void push(T element)
// Places element at the top of this stack.
{
LLNode<T> newNode = new LLNode<T>(element);
newNode.setLink(top);
top = newNode;
}
public void pop()
// Throws StackUnderflowException if this stack is empty,
// otherwise removes top element from this stack.
{
if (!isEmpty())
{
top = top.getLink();
}
else
throw new StackUnderflowException("Pop attempted on an empty stack.");
}
public T top()
// Throws StackUnderflowException if this stack is empty,
// otherwise returns top element from this stack.
{
if (!isEmpty())
return top.getInfo();
else
throw new StackUnderflowException("Top attempted on an empty stack.");
}
public boolean isEmpty()
// Returns true if this stack is empty, otherwise returns false.
{
if (top == null)
return true;
else
return false;
}
void push(LLNode<Integer> top) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void print()
{
LLNode<T> temp;
temp=top;
while(temp!=null)
{
System.out.println(temp.getInfo());
temp=temp.getLink();
}
}
public int sumLS()
{
LLNode<T> temp;
temp=top;
int sum=0;
while(temp!=null)
{
int x= (Integer)temp.getInfo();
sum=sum+x;
temp=temp.getLink();
}
return sum;
}
}


Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images

- A binary operator is an operation that is performed on two operands. For example, addition is a binary operator that adds two operands (e.g., 2 + 4). In the provided UML diagram, all binary operators have two operands and an execute method that performs the appropriate operation on the operands. The AddOperation class should add the two operands. The SubtractOperation class should subtract the two operands. Here is an example of how a binary operator could be used: IBinaryOperator operator = new AddOperator(8, 12);System.out.println(operator.execute()); // should print 20operator.setLeftOperand(18);System.out.println(operation.execute()); // should print 30 crate a Main.java to test your codearrow_forwardPlease answer the question in the screenshot. The language used here is in Java.arrow_forwardWritten in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forward
- Using C++ Without Using linked lists: Create a class AccessPoint with the following: x - a double representing the x coordinate y - a double representing the y coordinate range - an integer representing the coverage radius status - On or Off Add constructors. The default constructor should create an access point object at position (0.0, 0.0), coverage radius 0, and Off. Add accessor and mutator functions: getX, getY, getRange, getStatus, setX, setY, setRange and setStatus. Add a set function that sets the location coordinates and the range. Add the following member functions: move and coverageArea. Add a function overLap that checks if two access points overlap their coverage and returns true if they do. Add a function signalStrength that returns the wireless signal strength as a percentage. The signal strength decreases as one moves away from the access point location. Represent this with bars like, IIIII. Each bar can represent 20% Test your class by writing a main function that…arrow_forwarda java assignment about 4 used defined exception using array loop based on real life scenario. (use only java)arrow_forwardCan you please help with this Use the provided template below BASE_YEAR = 1903 #***************************************************************# Function: main# # Description: The main function of the program## Parameters: None## Returns: Nothing ##**************************************************************def main():# Local dictionary variablesyear_dict = {}count_dict = {}developerInfo()# Open the file for readinginput_file = open('Program11.txt', 'r') # End of the main function #*********************************************## Function: # # Description: ## Parameters:## Returns: ##*****************************************def showResults(year_dict, count_dict):# Receive user inputyear = int(input('Enter a year in the range 1903-2018: ')) # Print resultsif year == 1904 or year == 1994:print("The world series wasn't played in the year", year)elif year < 1903 or year > 2018:print('The data for the year', year, \'is not included in our database.')else:winner = year_dict[year]wins…arrow_forward
- Lab 10 Using an interface to share methods It is often the case that two or more classes share a common set of methods. For programming purposes we might wish to treat the objects of those classes in a similar way by invoking some of their common routines.For example, the Dog and Cat classes listed below agree on the void method speak. Because Dog and Cat objects have the ability to “speak,” it is natural to think of putting both types of objects in an ArrayList and invoking speak on every object in the list. Is this possible? Certainly we could create an ArrayList of Dog that would hold all the Dog objects, but can we then add a Cat object to an ArrayList of Dog?Try running the main program below as it is written. Run it a second time after uncommenting the line that instantiates a Cat object and tries to add it to the ArrayList. import java.util.*;public class AnimalRunner{ public static void main(String[] args) { ArrayList<Dog> dogcatList = new ArrayList<Dog>();…arrow_forwardImplement a nested class composition relationship between any two class types from the following list: Advisor Вook Classroom Department Friend Grade School Student Teacher Tutor Write all necessary code for both classes to demonstrate a nested composition relationship including the following: a. one encapsulated data member for each class b. inline default constructor using constructor delegation for each class c. inline one-parameter constructor for each class d. inline accessors for all data members e. inline mutators for all data membersarrow_forwardpackage lab1; /** * A utility class containing several recursive methods * * <pre> * * For all methods in this API, you are forbidden to use any loops, * String or List based methods such as "contains", or methods that use regular expressions * </pre> * * */ public final class Lab1 { /** * This is empty by design, Lab class cannot be instantiated */ privateLab1(){ // empty by design } /** * Returns the product of a consecutive set of numbers from <code> start </code> * to <code> end </code>. * * @param start is an integer number * @param end is an integer number * @return the product of start * (start + 1) * ..*. + end * @pre. * <code> start </code> and <code> end </code> are small enough to let * this method return an int. This means the return value at most * requires 4 bytes and no overflow would happen. */ publicstaticintproduct(ints,inte){ if(s==e){ returne; }else{ returns*product(s+1,e); } }…arrow_forward
- Written in Python with docstring please if applicable Thank youarrow_forwardEach object that is created from its "template" is called a(n) ?arrow_forwardProgram #11. Show the ArrayStackADT interface 2. Create the ArrayStackDataStrucClass<T> with the following methods: default constructor, overloaded constructor, copy constructor, initializeStack, isEmptyStack, isFullStack, push, peek, void pop 3. Create the PrimeFactorizationDemoClass: instantiate an ArrayStackDataStrucClass<Integer> object with 50 elements. Use a try-catch block in the main( ) using pushes/pops. 4. Exception classes: StackException, StackUnderflowException, StackOverflowException 5. Show the 4 outputs for the following: 3,960 1,234 222,222 13,780arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





