I need help with this code working Create another project and add yo.pdffantoosh1
I need help with this code working Create another project and add your jar file in this project. In
the main method of App class of this second project test your MyArrayList class. It is mandatory
to follow the instructions to get full credit. You need to perform the following actions. 1. Create
five strings, A1",,'B2",,'C3",'D4",'E5" 2. Save these Strings in your MyArrayList 3. Print a
message "Displaying List" 4. Display the list 5. Insert another String in your MyArrayList at
location 2 6. Print a message "Inserting Item" 7. Display the list 8. Remove String at location 0 9.
Print a message "Removing Item" 10. Display the list 11. Print a message "Setting a String" 12.
Set a new String in location 1 13. Display the list 14. Check whether "D4" is present in the list or
not, print an appropriate message 15. Find the index of "E5" in your list, print an appropriate
message 16. Print a message "Emptying List" 17. Empty the list 18. Print the size of the list
These steps check most of your MyArrayList functionality. I will also perform my own checks of
your code while grading. Deliverable: a. Copy the utils.jar file in your project folder. b. Make a
zip file of full project, not the src folder only or java files only. c. Submit the zip file. Grading
Rubric: The project is not submitted as required: 0 points
st.java J MyArrayList.java 2 J App.java 2 J MyFile.java 2 rc >J MyArrayList.java >q&
MyArrayList > get(int) public class MyArrayList implements MyList \{ Object [] obj = new
Object [1]; int size; public int size()\{ return size; \} public object get(int index) if (index <0
index >= size ){// throw new indexo return obj [index]; \} return index; // this should be deleted
after public void add (Object 0 ) \{ //if this test fails there is a space in the array. // it will pass
itself. if ( size == obj. length ){ Object [] obj2 = new 0 bject [obj. length 2]; for(int i=0;i<0bj.
length; i++){ obj2[i]=obj [i] ; \} obj=obj2; \} obj [ size ]=0; size++; \} public void add(int index,
Object o) \{ if(index > size || index <0 ) \{ throw new IndexOut0fBoundsException(index); \} if
(size == obj. length ){ Object [] obj2 = new Object [obj. length 2 ]; for(int i=0;i<0bj. length;
i++){ obj 2[i]=obj[i]; \} obj=obj2; \} if (index i=size;i>= index; i){ nhi [i=nhii1 : Ln 16, Col 56
Spaces: 4 UTF-8 LF \{\} Java
In this lab you will add an interface to the MyUtils project, and implement it in your
MyArrayList class in the MyUtils project. You will test the newly added functionality of your
MyArrayList class in another project. The UML for the Interface is as follows S Description of
methods Following method are self-explanatory: size(), get(int index), add (object o), remove
(int index), and isEmpty). Below is the description of all other methods. void add(int index,
Object o) inserts the given reference of object o at location index, making all entries move down
a spot. void remove (Object o) removes the first occurrence of object o in the list, moving all
entries .
project2/.classpath
project2/.project
project2
linklist
org.eclipse.jdt.core.javabuilder
org.eclipse.jdt.core.javanature
project2/bin/project2/emplist.classpackage project2;
publicsynchronizedclass emplist {
public void emplist();
publicstatic void main(String[]) throws java.io.IOException;
}
project2/bin/project2/method1.classpackage project2;
publicsynchronizedclass method1 {
java.util.LinkedList newList;
public void method1();
void reverse(java.util.LinkedList);
void downsize(java.util.LinkedList, int);
}
project2/employees.txt
Ahmed
Bill
Diana
Harry
Juliet
Nina
Romeo
Sam
Tom
Zack
project2/src/project2/emplist.javaproject2/src/project2/emplist.javapackage project2;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.ListIterator;
publicclass emplist {
publicstaticvoid main(String[] args)throwsIOException{
// TODO Auto-generated method stub
LinkedList<String> linkedlist =newLinkedList<String>();
method1 obj =new method1();
System.out.println("\t\t\t********************************************************");
System.out.println("\t\t\t********* This Program was written by ziyad **********");
System.out.println("\t\t\t********************************************************");
try(BufferedReader br =newBufferedReader(newFileReader(
"employees.txt"))){
String sCurrentLine;
while((sCurrentLine = br.readLine())!=null){
// System.out.println(sCurrentLine);
linkedlist.add(sCurrentLine);
// System.out.println(linkedlist);
}
String firstElement = linkedlist.get(0);
String lastElement = linkedlist.getLast();
System.out.println("\tDisplaying List contentusing traditional for loop");
for(int i =0; i < linkedlist.size(); i++){
System.out.println("Name of Emp is "+ linkedlist.get(i));
}
System.out.println("The first element of the List: "+ firstElement);
System.out.println("The last element of the List: "+ lastElement);
System.out.println("The size of the list after removing the last element Zack is: 9");
System.out.println("\tDisplaying using by using enhances for loop: ");
for(int a =0; a < linkedlist.size(); a++){
System.out.println(linkedlist.get(a));
}
ListIterator iter = linkedlist.listIterator();
while(iter.hasNext()){
int i = iter.nextIndex();
iter.next();
// System.out.println(iter.next() + " is at index" + i);
if(i ==0){
System.out.println("The current emplyee after advancing the iter five timers is: "
+ iter.previous());
Object element = iter.next();
iter.add("kelly");
// iter.set( "Kelly");
int k =0;
// while( k < linkedlist.size())
{
System.out.println("\tDisplaying list after inserting Kelly after the fifth position\n"+ linkedlist +" ");
k++;
}
}elseif(i ==6){
System.out.println("\tDisplaying list after setting the current element to Nancy"+ iter.previous());
Object element1 = iter.next();
.
Sorted number list implementation with linked listsStep 1 Inspec.pdfalmaniaeyewear
Sorted number list implementation with linked lists
Step 1: Inspect the Node.java file
Inspect the class declaration for a doubly-linked list node in Node.java. Access Node.java by
clicking on the orange arrow next to LabProgram.java at the top of the coding window. The
Node class has three fields:
a double data value,
a reference to the next node, and
a reference to the previous node.
Each field is protected. So code outside of the class must use the provided getter and setter
methods to get or set a field.
Node.java is read only, since no changes are required.
Step 2: Implement the insert() method
A class for a sorted, doubly-linked list is declared in SortedNumberList.java. Implement the
SortedNumberList class's insert() method. The method must create a new node with the
parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then insert(33.5) is called. A new
node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the remove() method
Implement the SortedNumberList class's remove() method. The method takes a parameter for the
number to be removed from the list. If the number does not exist in the list, the list is not
changed and false is returned. Otherwise, the first instance of the number is removed from the
list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
Given templates:
LabProgram.java
import java.util.Scanner;
import java.io.PrintWriter;
public class LabProgram {
// Prints the SortedNumberList's contents, in order from head to tail
public static void printList(SortedNumberList list) {
Node node = list.head;
while (null != node) {
System.out.print(node.getData() + " ");
node = node.getNext();
}
System.out.println();
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String inputLine;
// Read the line of input numbers
inputLine = scnr.nextLine();
// Split on space character
String[] terms = inputLine.split(" ");
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list = new SortedNumberList();
for (Object term : terms) {
double number = Double.parseDouble(term.toString());
System.out.println("List after inserting " + number + ": ");
list.insert(number);
printList(list);
}
/*
// Read the input line with numbers to remove
inputLine = scnr.nextLine();
terms = inputLine.split(" ".
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
Need done for Date Structures please!
4.18 LAB: Sorted number list implementation with linked lists
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node
with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector<string> SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector<string> terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number.
Required to augment the authors Binary Search Tree (BST) code to .docxdebishakespeare
Required to augment the author's Binary Search Tree (BST) code to support these new operations. Method names below are merely suggestions. (The author’s class is attached separately in the file called “authordoc”. I just built a simple test tree in the author’s main method which can be used to test the various operations. )
1. AnyType nthElement(int n) -- returns the n-th element (starting from 1) of the in-order traversal of the BST.
2. int rank( AnyType x ) -- returns the "rank" of x. The rank of an element is its position (starting with 1) in an in-order traversal.
3. AnyType median( ) -- returns the median (middle) element in the BST. If the BST contains an even number of elements, returns the smaller of the two medians.
4. boolean isPerfect( ) -- returns true if the BST is a perfect binary tree.
5. boolean isComplete( ) -- returns true if the BST is a complete binary tree.
6. String toString( int nrLevels ) -- generates the level-order output described in the sample output below.
Most of these operations could easily be implemented by performing an in-order traversal inside the BST and perhaps placing the results in an ArrayList. However, such a method is extremely inefficient. Instead, we are going to achieve faster performance by "augmenting" the BST nodes. You will add a new private integer data member ("tree size") to the BinaryNode which stores the size of the tree rooted at that node (including the root). You must develop your own algorithms for these operations, but obviously you will use the new tree size data member to guide your search. Think before you code and think recursively!
These items cover those topics not addressed elsewhere in the project description. (R) indicates a requirement, (H) indicates a hint, and (N) indicates a note.
1. (R) Although we are only using the BST for integers, the BST must remain a generic class.
2. (R) Duplicate values are not allowed. Attempts to insert a duplicate value should be ignored.
3. (R) Attempts to remove non-existent values should be ignored.
4. (R) From a coding perspective, the easiest way to avoid duplicate insertions or attempting to remove non-existent elements is to first call find( ). However, this technique is NOT permitted for two reasons.
Calling find( ) before each insert/remove doubles the running time for these operations and is therefore inefficient.
Recusively coding the insert/remove methods to handle these situations is a great learning experience.
5. (R) The level order print (PRINT command) outputs the value of each node, the size of the tree rooted at that node, and the value of the node's parent in that order, inside parenthesis, separated by commas. (node value, tree size, parent value). Since the root has no parent, print NULL for the root's parent value. For readability, separate the levels with a blank line and print no more than 6 node/size/parent values per line. If a level requires multiple lines, use consecutive lines (without a blank line between the ...
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
Getting Started
Create a class called Lab8. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file Lab8.java. Additionally, make
another file called Arrays.java. This file will be an object, so simply start it off by declaring an
Arrays class. You can copy the following skeleton and fill in the appropriate code below each of
the comments:
public class Arrays {
/ Instance Variables
// Constructors
// findMin 1
// findMax
// calcSum
// calcAverage
// toString
}
Task Overview
Your task for this lab is to create a class called Arrays with some array processing methods. This
class will maintain an array and the number of elements present in it. Additionally, methods will
be available to display the current min and max elements along with the average of all of them.
Finally, a toString() method will be available to cleanly display all the array elements. Finally,
you will write a simple driver class to test out the above Arrays class.
Part 1: Instance Variables for Arrays
The first thing to do for the Arrays class is to set up its instance variables. Declare the following
(private) instance variables:
• An int array called array ? this will be the array we will be writing methods for.
• An int called count - this represents the number of valid elements in the array.
Part 2:
Constructors for Arrays The Arrays class will have two constructors. The first constructor takes
the maximum size of the array as input as a parameter and initializes the array instance variable
appropriately. It also sets count to size. Finally, it will initialize all of the array elements to some
values between 0 and 10, inclusive. To create this constructor, follow these steps:
• Import java.util.Random to make use of the random number generator.
• Create a constructor with the following header: public Arrays(int size)
• Initialize your array variable and set its size to size (see the chart on page 252 for reference on
initializing arrays). Be very careful that you are setting the value of your array instance variable,
as opposed to creating a new variable called array.
• Set the value of the count variable to size because we will be populating the entire array.
• Copy the following code to the constructor in order to generate random values between 0 and
10, inclusive:
Random rand = new Random();
for (int i = 0; i < count; i++)
{
array[i] = (rand.nextInt(10));
}
Next, create another constructor with the following header: public Arrays(int[] arr). This
constructor will initialize the class by using the passed arr argument in order to fill its instance
variables. The following things need to be done inside of this constructor:
• Set the array variable equal to arr.
• Set the count variable equal to the length of the array.
Part 3: Displaying the Output findMin()
The first method of this class will search the array for the minimum element. Copy the following
code for the findMin method. Note how the count i.
I need help with this code working Create another project and add yo.pdffantoosh1
I need help with this code working Create another project and add your jar file in this project. In
the main method of App class of this second project test your MyArrayList class. It is mandatory
to follow the instructions to get full credit. You need to perform the following actions. 1. Create
five strings, A1",,'B2",,'C3",'D4",'E5" 2. Save these Strings in your MyArrayList 3. Print a
message "Displaying List" 4. Display the list 5. Insert another String in your MyArrayList at
location 2 6. Print a message "Inserting Item" 7. Display the list 8. Remove String at location 0 9.
Print a message "Removing Item" 10. Display the list 11. Print a message "Setting a String" 12.
Set a new String in location 1 13. Display the list 14. Check whether "D4" is present in the list or
not, print an appropriate message 15. Find the index of "E5" in your list, print an appropriate
message 16. Print a message "Emptying List" 17. Empty the list 18. Print the size of the list
These steps check most of your MyArrayList functionality. I will also perform my own checks of
your code while grading. Deliverable: a. Copy the utils.jar file in your project folder. b. Make a
zip file of full project, not the src folder only or java files only. c. Submit the zip file. Grading
Rubric: The project is not submitted as required: 0 points
st.java J MyArrayList.java 2 J App.java 2 J MyFile.java 2 rc >J MyArrayList.java >q&
MyArrayList > get(int) public class MyArrayList implements MyList \{ Object [] obj = new
Object [1]; int size; public int size()\{ return size; \} public object get(int index) if (index <0
index >= size ){// throw new indexo return obj [index]; \} return index; // this should be deleted
after public void add (Object 0 ) \{ //if this test fails there is a space in the array. // it will pass
itself. if ( size == obj. length ){ Object [] obj2 = new 0 bject [obj. length 2]; for(int i=0;i<0bj.
length; i++){ obj2[i]=obj [i] ; \} obj=obj2; \} obj [ size ]=0; size++; \} public void add(int index,
Object o) \{ if(index > size || index <0 ) \{ throw new IndexOut0fBoundsException(index); \} if
(size == obj. length ){ Object [] obj2 = new Object [obj. length 2 ]; for(int i=0;i<0bj. length;
i++){ obj 2[i]=obj[i]; \} obj=obj2; \} if (index i=size;i>= index; i){ nhi [i=nhii1 : Ln 16, Col 56
Spaces: 4 UTF-8 LF \{\} Java
In this lab you will add an interface to the MyUtils project, and implement it in your
MyArrayList class in the MyUtils project. You will test the newly added functionality of your
MyArrayList class in another project. The UML for the Interface is as follows S Description of
methods Following method are self-explanatory: size(), get(int index), add (object o), remove
(int index), and isEmpty). Below is the description of all other methods. void add(int index,
Object o) inserts the given reference of object o at location index, making all entries move down
a spot. void remove (Object o) removes the first occurrence of object o in the list, moving all
entries .
project2/.classpath
project2/.project
project2
linklist
org.eclipse.jdt.core.javabuilder
org.eclipse.jdt.core.javanature
project2/bin/project2/emplist.classpackage project2;
publicsynchronizedclass emplist {
public void emplist();
publicstatic void main(String[]) throws java.io.IOException;
}
project2/bin/project2/method1.classpackage project2;
publicsynchronizedclass method1 {
java.util.LinkedList newList;
public void method1();
void reverse(java.util.LinkedList);
void downsize(java.util.LinkedList, int);
}
project2/employees.txt
Ahmed
Bill
Diana
Harry
Juliet
Nina
Romeo
Sam
Tom
Zack
project2/src/project2/emplist.javaproject2/src/project2/emplist.javapackage project2;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.ListIterator;
publicclass emplist {
publicstaticvoid main(String[] args)throwsIOException{
// TODO Auto-generated method stub
LinkedList<String> linkedlist =newLinkedList<String>();
method1 obj =new method1();
System.out.println("\t\t\t********************************************************");
System.out.println("\t\t\t********* This Program was written by ziyad **********");
System.out.println("\t\t\t********************************************************");
try(BufferedReader br =newBufferedReader(newFileReader(
"employees.txt"))){
String sCurrentLine;
while((sCurrentLine = br.readLine())!=null){
// System.out.println(sCurrentLine);
linkedlist.add(sCurrentLine);
// System.out.println(linkedlist);
}
String firstElement = linkedlist.get(0);
String lastElement = linkedlist.getLast();
System.out.println("\tDisplaying List contentusing traditional for loop");
for(int i =0; i < linkedlist.size(); i++){
System.out.println("Name of Emp is "+ linkedlist.get(i));
}
System.out.println("The first element of the List: "+ firstElement);
System.out.println("The last element of the List: "+ lastElement);
System.out.println("The size of the list after removing the last element Zack is: 9");
System.out.println("\tDisplaying using by using enhances for loop: ");
for(int a =0; a < linkedlist.size(); a++){
System.out.println(linkedlist.get(a));
}
ListIterator iter = linkedlist.listIterator();
while(iter.hasNext()){
int i = iter.nextIndex();
iter.next();
// System.out.println(iter.next() + " is at index" + i);
if(i ==0){
System.out.println("The current emplyee after advancing the iter five timers is: "
+ iter.previous());
Object element = iter.next();
iter.add("kelly");
// iter.set( "Kelly");
int k =0;
// while( k < linkedlist.size())
{
System.out.println("\tDisplaying list after inserting Kelly after the fifth position\n"+ linkedlist +" ");
k++;
}
}elseif(i ==6){
System.out.println("\tDisplaying list after setting the current element to Nancy"+ iter.previous());
Object element1 = iter.next();
.
Sorted number list implementation with linked listsStep 1 Inspec.pdfalmaniaeyewear
Sorted number list implementation with linked lists
Step 1: Inspect the Node.java file
Inspect the class declaration for a doubly-linked list node in Node.java. Access Node.java by
clicking on the orange arrow next to LabProgram.java at the top of the coding window. The
Node class has three fields:
a double data value,
a reference to the next node, and
a reference to the previous node.
Each field is protected. So code outside of the class must use the provided getter and setter
methods to get or set a field.
Node.java is read only, since no changes are required.
Step 2: Implement the insert() method
A class for a sorted, doubly-linked list is declared in SortedNumberList.java. Implement the
SortedNumberList class's insert() method. The method must create a new node with the
parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then insert(33.5) is called. A new
node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the remove() method
Implement the SortedNumberList class's remove() method. The method takes a parameter for the
number to be removed from the list. If the number does not exist in the list, the list is not
changed and false is returned. Otherwise, the first instance of the number is removed from the
list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
Given templates:
LabProgram.java
import java.util.Scanner;
import java.io.PrintWriter;
public class LabProgram {
// Prints the SortedNumberList's contents, in order from head to tail
public static void printList(SortedNumberList list) {
Node node = list.head;
while (null != node) {
System.out.print(node.getData() + " ");
node = node.getNext();
}
System.out.println();
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String inputLine;
// Read the line of input numbers
inputLine = scnr.nextLine();
// Split on space character
String[] terms = inputLine.split(" ");
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list = new SortedNumberList();
for (Object term : terms) {
double number = Double.parseDouble(term.toString());
System.out.println("List after inserting " + number + ": ");
list.insert(number);
printList(list);
}
/*
// Read the input line with numbers to remove
inputLine = scnr.nextLine();
terms = inputLine.split(" ".
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
Need done for Date Structures please!
4.18 LAB: Sorted number list implementation with linked lists
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node
with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector<string> SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector<string> terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number.
Required to augment the authors Binary Search Tree (BST) code to .docxdebishakespeare
Required to augment the author's Binary Search Tree (BST) code to support these new operations. Method names below are merely suggestions. (The author’s class is attached separately in the file called “authordoc”. I just built a simple test tree in the author’s main method which can be used to test the various operations. )
1. AnyType nthElement(int n) -- returns the n-th element (starting from 1) of the in-order traversal of the BST.
2. int rank( AnyType x ) -- returns the "rank" of x. The rank of an element is its position (starting with 1) in an in-order traversal.
3. AnyType median( ) -- returns the median (middle) element in the BST. If the BST contains an even number of elements, returns the smaller of the two medians.
4. boolean isPerfect( ) -- returns true if the BST is a perfect binary tree.
5. boolean isComplete( ) -- returns true if the BST is a complete binary tree.
6. String toString( int nrLevels ) -- generates the level-order output described in the sample output below.
Most of these operations could easily be implemented by performing an in-order traversal inside the BST and perhaps placing the results in an ArrayList. However, such a method is extremely inefficient. Instead, we are going to achieve faster performance by "augmenting" the BST nodes. You will add a new private integer data member ("tree size") to the BinaryNode which stores the size of the tree rooted at that node (including the root). You must develop your own algorithms for these operations, but obviously you will use the new tree size data member to guide your search. Think before you code and think recursively!
These items cover those topics not addressed elsewhere in the project description. (R) indicates a requirement, (H) indicates a hint, and (N) indicates a note.
1. (R) Although we are only using the BST for integers, the BST must remain a generic class.
2. (R) Duplicate values are not allowed. Attempts to insert a duplicate value should be ignored.
3. (R) Attempts to remove non-existent values should be ignored.
4. (R) From a coding perspective, the easiest way to avoid duplicate insertions or attempting to remove non-existent elements is to first call find( ). However, this technique is NOT permitted for two reasons.
Calling find( ) before each insert/remove doubles the running time for these operations and is therefore inefficient.
Recusively coding the insert/remove methods to handle these situations is a great learning experience.
5. (R) The level order print (PRINT command) outputs the value of each node, the size of the tree rooted at that node, and the value of the node's parent in that order, inside parenthesis, separated by commas. (node value, tree size, parent value). Since the root has no parent, print NULL for the root's parent value. For readability, separate the levels with a blank line and print no more than 6 node/size/parent values per line. If a level requires multiple lines, use consecutive lines (without a blank line between the ...
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
Getting Started
Create a class called Lab8. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file Lab8.java. Additionally, make
another file called Arrays.java. This file will be an object, so simply start it off by declaring an
Arrays class. You can copy the following skeleton and fill in the appropriate code below each of
the comments:
public class Arrays {
/ Instance Variables
// Constructors
// findMin 1
// findMax
// calcSum
// calcAverage
// toString
}
Task Overview
Your task for this lab is to create a class called Arrays with some array processing methods. This
class will maintain an array and the number of elements present in it. Additionally, methods will
be available to display the current min and max elements along with the average of all of them.
Finally, a toString() method will be available to cleanly display all the array elements. Finally,
you will write a simple driver class to test out the above Arrays class.
Part 1: Instance Variables for Arrays
The first thing to do for the Arrays class is to set up its instance variables. Declare the following
(private) instance variables:
• An int array called array ? this will be the array we will be writing methods for.
• An int called count - this represents the number of valid elements in the array.
Part 2:
Constructors for Arrays The Arrays class will have two constructors. The first constructor takes
the maximum size of the array as input as a parameter and initializes the array instance variable
appropriately. It also sets count to size. Finally, it will initialize all of the array elements to some
values between 0 and 10, inclusive. To create this constructor, follow these steps:
• Import java.util.Random to make use of the random number generator.
• Create a constructor with the following header: public Arrays(int size)
• Initialize your array variable and set its size to size (see the chart on page 252 for reference on
initializing arrays). Be very careful that you are setting the value of your array instance variable,
as opposed to creating a new variable called array.
• Set the value of the count variable to size because we will be populating the entire array.
• Copy the following code to the constructor in order to generate random values between 0 and
10, inclusive:
Random rand = new Random();
for (int i = 0; i < count; i++)
{
array[i] = (rand.nextInt(10));
}
Next, create another constructor with the following header: public Arrays(int[] arr). This
constructor will initialize the class by using the passed arr argument in order to fill its instance
variables. The following things need to be done inside of this constructor:
• Set the array variable equal to arr.
• Set the count variable equal to the length of the array.
Part 3: Displaying the Output findMin()
The first method of this class will search the array for the minimum element. Copy the following
code for the findMin method. Note how the count i.
File LinkedList.java Defines a doubly-l.pdfConint29
File: LinkedList.java
/**
* Defines a doubly-linked list class
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition
* @return the value stored at node first
* @throws NoSuchElementException
*/
public T getFirst() throws NoSuchElementException {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @pos.
Need Help with this Java Assignment. Program should be done in JAVA .pdfarchiesgallery
Need Help with this Java Assignment. Program should be done in JAVA please
Complete required scripts based on eclipse and troubleshoot the scripts until the tasks are done.
1. Implement a binary search tree (write the code for it), for a height of 2 or higher. Please show
the output if you can Thank you in advance!
Solution
I have compiled this code and checked for errors, worked fine.
Also after the code I have pasted the Output transcript to show what User Inputs I gave and what
all outputs I got.
// Java Program to Implement Binary Tree
import java.util.Scanner;
/* Define Class BinaryTreeNode */
class BinaryTreeNode
{
BinaryTreeNode left, right;
int data;
/* Constructor */
public BinaryTreeNode()
{
left = null;
right = null;
data = 0;
}
/* Constructor */
public BinaryTreeNode(int n)
{
left = null;
right = null;
data = n;
}
/* Function to set left node */
public void setLeft(BinaryTreeNode n)
{
left = n;
}
/* Function to set right node */
public void setRight(BinaryTreeNode n)
{
right = n;
}
/* Function to get left node */
public BinaryTreeNode getLeft()
{
return left;
}
/* Function to get right node */
public BinaryTreeNode getRight()
{
return right;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Define anothe Class Operations to perform required operationns on Binary Tree*/
class Operations
{
private BinaryTreeNode root;
/* Constructor */
public Operations()
{
root = null;
}
/* Function to check if tree is empty */
public boolean isEmpty()
{
return root == null;
}
/* Functions to insert data */
public void insert(int data)
{
root = insert(root, data);
}
/* Function to insert data recursively */
private BinaryTreeNode insert(BinaryTreeNode node, int data)
{
if (node == null)
node = new BinaryTreeNode(data);
else
{
if (node.getRight() == null)
node.right = insert(node.right, data);
else
node.left = insert(node.left, data);
}
return node;
}
/* Function to count number of nodes */
public int countNodes()
{
return countNodes(root);
}
/* Function to count number of nodes recursively */
private int countNodes(BinaryTreeNode r)
{
if (r == null)
return 0;
else
{
int l = 1;
l += countNodes(r.getLeft());
l += countNodes(r.getRight());
return l;
}
}
/* Function to search for an element */
public boolean search(int val)
{
return search(root, val);
}
/* Function to search for an element recursively */
private boolean search(BinaryTreeNode r, int val)
{
if (r.getData() == val)
return true;
if (r.getLeft() != null)
if (search(r.getLeft(), val))
return true;
if (r.getRight() != null)
if (search(r.getRight(), val))
return true;
return false;
}
/* Function for inorder traversal */
public void inorder()
{
inorder(root);
}
private void inorder(BinaryTreeNode r)
{
if (r != null)
{
inorder(r.getLeft());
System.out.print(r.getData() +\" \");
inorder(r.getRight());
}
}
/* Function for preorder traversal */
public void preorder()
{
preorder(root);
}
priva.
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
Write a Java Class to Implement a Generic Linked List
Your list must be implemented as a singly-linked list of generic nodes, where each Node object
has two instance variables: an object of the “type variable” class, and a pointer to the next node
on the list.
Your class will contain separate methods to handle each of the operations read from a data file
(see II., below)
Your class will also override toString() to return the objects on the list in the order in which they
occur.
Write a Test Class for Your LinkedList Class
Your main method will read list operation instructions from a data file, until end-of-file and call
the appropriate LinkedList method to execute each one.
After each operation is executed, print out the operation and the updated list.
The data file to be used is on the class web site and the operations are:
APPEND X - Append object X to the end of the list
ADD N X - Insert object X as the new Nth element in the list, increasing the size of the list by 1
E.g. Suppose the list is:
head -> 1 -> 2 -> 3 -> 4->null
After ADD 3 7 it would be:
head -> 1 -> 2 -> 7 -> 3 -> 4->null
DELETE N – Remove the Nth object from the list
SWAP M N - Interchange the positions of the Mth and Nth
objects on the list
For credit, the two nodes must actually \"trade places\" in the list, and not merely swap their data
values
REVERSE - Reverse the order of the objects on the list
This must be done by reversing the order of the nodes themselves, rather than by swapping the
data stored
To get credit for your reverse() method, it must use either one of these 2 algorithms:
For each node on the list except the current “head”
node, delete the node and insert it as the new head
Use your swap() method
6. CLEAR – Clear the list (make it empty)
No credit will be given for programs that use any additional data structures – either from the Java
API or programmer defined -, other than your own LinkedList class
txt file:
Solution
//Java Program to Implement Singly Linked List
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/* Class Node */
class Nodes
{
protected Object data;
protected Nodes next;
/* Constructor */
public Nodes()
{
next = null;
data = null;
}
/* Constructor */
public Nodes(Object d,Nodes n)
{
data = d;
next = n;
}
/* Function to set link to next Node */
public void setLink(Nodes n)
{
next = n;
}
/* Function to set data to current Node */
public void setData(Object d)
{
data = d;
}
/* Function to get link to next node */
public Nodes getLink()
{
return next;
}
/* Function to get data from current Node */
public Object getData()
{
return data;
}
}
/* Class linkedList */
class linkList
{
protected Nodes start;
protected Nodes end ;
public int size ;
/* Constructor */
public linkList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isEmpty()
{
return start == null;
}
/* Function to get size of list */
public int getSize()
{
return .
Java Programming- 1) Write a recursive method that finds and returns t.docxmichael1810
Java Programming:
1) Write a recursive method that finds and returns the sum of the elements in an int array. Also, write a program to test your method
** Please simple enough for a beginner to understand
Solution
/**
* @author
*
*/
public class RecusrsiveArraySum {
/**
* @param args
*/
public static void main(String[] args) {
int arr[] = { 3, 4, 6, 7 };
System.out
.println(\"Sum of array Elements: \" + sum(arr, arr.length - 1));
}
/**
* recursive sum of array elements
*
* @param array
* @param index
* @return
*/
public static int sum(int[] array, int index) {
// if array is empty
if (index < 0)
return 0;
if (index == 0) {
// when no index reaches first element
return array[0];
} else {
// adding array elements
return array[index] + sum(array, index - 1);
}
}
}
OUTPUT:
Sum of array Elements: 20
.
Using Array Approach, Linked List approach, and Delete Byte Approach.pdffms12345
Use the graph of the function f below to find the following. All local minimum values of f All
values at which f has a local minimum If there is more than one answer, separate them with
commas. All local minimum values of f All values at which f has a local minimum:
Solution
Dear student
Thank you for using Chegg
As per the given curve it is clear that the local minimum values of f are -3 & 0
Values of x when curve attain minimum values are x = -2,3.
Write a function which return a list of all of the n element subset .pdfhardjasonoco14599
Write a function which return a list of all of the n element subset of a given set
Implement in JAVA Question 3 Write a function that returns a list of all of the n-element subsets
of a given set. For example, if the given set is [1,2,3] and n is 2, then the returned list should
contain [1,2], [1,3], and [2,3]. The order of the elements is not important.
Solution
The program for this problem is as follows:
Comments are included in the program for explaining the steps.
A sample output is attached below the program.
package com.temp;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* Program to find sublists of a list.
* @author Rohit Phatak
*
*/
public class subset {
/**
* This list will contain the resultant sublists.
*/
static List list = new ArrayList<>();
public static void main(String arg[]){
/**
* Input a list comma separated.
*/
System.out.println(\"Enter a list : \");
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] sArr = s.split(\",\");
/**
* Input a value of n.
*/
System.out.println(\"Enter value of n : \");
Integer n = scanner.nextInt();
/**
* Check if value of n is greater than entered list.
*/
if(sArr.length < n){
System.out.println(\"Length of list is less than value of n\");
} else if(sArr.length > 0){
getSubsetList(sArr,n);
System.out.println(\"List is as :\");
/**
* Printing the sublists.
*/
for(String[] str : list){
String printVar = \"\";
for(String temps : str)
printVar+=temps+\",\";
System.out.println(\"[\"+printVar.substring(0, printVar.length()-1)+\"]\");
}
} else {
System.out.println(\"Please enter atleast one element:\");
}
scanner.close();
}
/**
* This method calls the recursive function which is used to obtain the sublists.
* @param sArr
* @param n
* @return
*/
public static List getSubsetList(String[] sArr,Integer n){
List lista = new ArrayList<>();
sublist(sArr, 0, n, new String[n]);
return lista;
}
/**
* This is a recursive function.
* This function will iterate over itself for finding the sublist.
*
* Parameters are as follows:
*
* @param arr -> List entered by the user.
* @param n -> Value of sublist entered by user.
* @param startPosition -> index to start creating the sublist.
* @param result -> resultant sublist
*/
public static void sublist(String[] arr, int startPosition, int n, String[] result){
/**
* Check for the value of n ==0.
* If n==0 break from the recursion.
*/
if (n == 0){
/**
* Add the sublist \'result\' in the list.
*/
list.add(result.clone());
return;
}
/**
* Iterate through for loop starting from startPosition till length of list minus entered value
n.
*/
for (int i = startPosition; i <= arr.length-n; i++){
/**
* Here result is a temporary sublist.
* This for loop adds an element to the temporary sublist in each iteration.
* The element is added from the complete list entered by user.
* Location of element is iTh index.
*/
result[result.length - n] = arr[i];
/**
* After adding the element to the temporary sublist, the sublist an.
In java , I want you to implement a Data Structure known as a Doubly.pdfaromalcom
In java , I want you to implement a Data Structure known as a Doubly-Ended-Queue. it is a
“fair” data structure in that it implements a FIFO (First In First Out ) behavior. As such, it is
often used to implement various wait lists in computer systems. For example, jobs waiting to use
the CPU, jobs waiting for a printer, jobs waiting to be placed into RAM for execution. In short,
whenever we want a fair strategy for waiting we use queues.
A DEQUE (Doubly-ended-queue) is a related data structure. Although similar to a Queue, it
differs in that it allows for insertions AND deletions from either end of the list (both the front
and the rear).
Your implementation MUST use a doubly-linked-list implementation. You may not use a static
array implementation.
Thus, a Deque is a List but it is one which only concerns itself with the first and last positions for
any insertion or deletion. The 6 operations supported are :
public void insertFront( int item ) - insert the given item (as a node) into the first position of the
Deque.
public void insertRear( int item ) - insert the given item (as a node) into the last position of the
Deque.
public int deleteFront( ) - delete and return the element stored in the first node of the Deque.
public int deletRear( ) – delete and return the element stored in the last node of the Deque.
public boolean isempty( ) - returns true if the Deque is currently empty or false if it is not.
public void printDeque( ) - print the integers from the list, one per line, from the first element
through to the last in order.
Classes
Your program must implement the following 3 classes. public class dequeDriver
This class will contain your program’s main method. It will need to declare a deque object and
process input as indicated below.
Your program should prompt the user for the path of an input file. It should open the file for
input and process it line by line. Each line of the input file will have one of the following forms.
PR
IF
IR
DF
DR
The meanings of each input is as follows:
PR - print the current contents of the deque from front to rear using the printDeque( ) method of
the deque object.
IF - insert the given int value into the front of the deque.
IR - insert the given int value into the rear of the deque.
DF - delete the front value from the deque.
DR – delete the rear element of the deque.
Below is an example input file that your program should be able to process.
PR
IF 4
IF 5
IF 6
IR 7
PR
DR
PR
DF
PR
The output for the input file shown above is :
EMPTY DEQUE
----- Front -----
6
5
4
7
----- Rear -----
----- Front -----
6
5
4
----- Rear -----
----- Front -----
5
4
----- Rear -----
public class dequeNode
This class will implement the linked nodes that will be used to implement the deque itself.
It should have the following protected data members.
protected dequeNode next; // next pointer to next node
protected dequeNode prev; // previous pointer to previous node
protected int val; // the integer value stored within the dequeNod.
Labprogram.java
LinkedList.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
*
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
*
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
public T getFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator != null) {
return iterator.data;
} else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
public void addIterator(T data) throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("addIterator Iterator is off end.");
}
if (iterator == last) {
addLast(data);
} else {
Node newNode = new Node(data);
Node next = iterator.next;
newNode.next = next;
newNode.prev = iterator;
iterator.next = newNode;
next.prev = newNode;
length++;
}
}
public void removeFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == first) {
iterator = null;
}
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == last) {
iterator = null;
}
last = last.prev;
last.next = null;
}
length--;
}
public void removeIterator() throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("Iterator is off the end opf the list.");
}
if (iterator .
C++ (pronounced "see plus plus") is a computer programming language based on C. It was created for writing programs for many different purposes. In the 1990s, C++ became one of the most used programming languages in the world.
The C++ programming language was developed by Bjarne Stroustrup at Bell Labs in the 1980s, and was originally named "C with classes". The language was planned as an improvement on the C programming language, adding features based on object-oriented programming. Step by step, a lot of advanced features were added to the language, like operator overloading, exception handling and templates.
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
package singlylinkedlist;
public class Node {
public String value;
public Node next;
public Node(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
SingleyLinkedList.java :
package singlylinkedlist;
import java.io.*;
import java.util.*;
/**
* Defines the interface for a singly-linked list.
*
*/
public interface SinglyLinkedList {
/**
* @return Reference to the first node. If the list is empty, this method
* returns null.
*/
public Node getFirst();
/**
* @return Reference to the last node . If the list is empty, this method
* returns null.
*/
public Node getLast();
/**
* @return Number of nodes in the list
*/
public int size();
/**
* @return true if the list has no nodes; false otherwise
*/
public boolean isEmpty();
/**
* Removes all nodes in the list.
*/
public void clear();
/**
* Inserts a new node with the given value after cursor.
*
* @param cursor
* The node to insert after. Set this to null to insert value as
the
* new first Node.
* @param value
* The value to insert
* @return a reference to the newly inserted Node
*/
public Node insert(Node cursor, String value);
/**
* Inserts a new node with the given value at the "end" of the list.
*
* @param value
* @return a reference to the newly inserted Node
*/
public Node append(String value);
/**
* Removes the node after the specified Node (cursor) from the list.
*
* @param cursor
* A reference to the Node to remove.
*/
public void removeAfter(Node cursor);
/**
* Returns a reference to the first Node containing the key, starting from
the
* given Node.
*
* @param start
* @param key
* @return a reference to the first Node containing the key
*/
public Node find(Node start, String key);
/**
* Prints the values of all the items in a list
*/
public void printWholeList();
}
SinglyLinkedTester.java:
package sbccunittest;
import static java.lang.Math.*;
import static java.lang.System.*;
import static org.apache.commons.lang3.StringUtils.*;
import static org.junit.Assert.*;
import static sbcc.Core.*;
import java.io.*;
import java.lang.reflect.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
import org.apache.commons.lang3.*;
import org.junit.*;
import org.w3c.dom.ranges.*;
import sbcc.*;
import singlylinkedlist.*;
/**
* 09/16/2021
*
* @author sstrenn
*
*/
public class SinglyLinkedListTester {
public static String newline = System.getProperty("line.separator");
public static int totalScore = 0;
public static int extraCredit = 0;
public static boolean isZeroScore = false;
public static String scorePreamble = "";
@BeforeClass
public static void beforeTesting() {
totalScore = 0;
extraCredit = 0;
}
@AfterClass
public static void afterTesting() {
if (isZeroScore) {
totalScore = 0;
extraCredit = 0;
}
println(scorePreamble + "Estimated score (w/o late penalties, etc.) is:
" + totalScore + " out of 25.");
// If the project follows the naming convention, save the results in a
folder on
// the desktop. (Alex Kohanim)
try {
String directory =
substri.
Please help solve this in C++ So the program is working fin.pdfankit11134
Please help solve this in C++. So the program is working fine but when submitting it, it gives me a
code -11, and I believe the problem is that after inserting the numbers it removes them one by one
until the last in the list, and when it tries to remove the last number in the list that is when it
counters the problem. Below is the full code but you just need to change something in the
SortedNumberList.h file under the bool remove function.
4.18 LAB: Sorted number list implementation with linked lists Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking on
the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables: - a double data value, - a pointer to the next node, and - a pointer to the
previous node. Each member variable is protected. So code outside of the class must use the
provided getter and setter member functions to get or set a member variable. Node.h is read only,
since no changes are required. Step 2: Implement the Insert() member function A class for a
sorted, doubly-linked list is declared in SortedNumberList.h. Implement the SortedNumberList
class's Insert() member function. The function must create a new node with the parameter value,
then insert the node into the proper sorted position in the linked list. Ex: Suppose a
SortedNumberList's current list is 2347.2586, then Insert(33.5) is called. A new node with data
value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's sorted order
and yielding: 2335.547.2586Step 3: Test in develop mode Code in main() takes a space-
separated list of numbers and inserts each into a SortedNumberList. The list is displayed after
each insertion. Ex: If input is 77154263.5 then output is: List after inserting 77 : 77 List after
inserting 15 : 1577 List after inserting -42 : -421577 List after inserting 63.5: -421563.577 Try
various program inputs, ensuring that each outputs a sorted list. Step 4: Implement the Remove()
member function Implement the SortedNumberList class's Remove(0 member function. The
function takes a parameter for the number to be removed from the list. If the number does not
exist in the list, the list is not changed and false is returned. Otherwise, the first instance of the
number is removed from the list and true is returned. Uncomment the commented-out part in
main() that reads a second input line and removes numbers from the list. Test in develop mode to
ensure that insertion and removal both work properly, then submit code for grading. Ex: If input is
841972841961 then output is: List after inserting 84: 84 List after inserting 72 : 7284 List after
inserting 19: 1972 84 List after inserting 61: 1961 : 72 8 List after removing 19: 6172 84 List after
removing 84: 6172Current file: main.cpp - // Insert each value and show the sorted List's contents
after each insertion sortedNumberList list; for (auto term : terms) { doubl.
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
Solid waste management & Types of Basic civil Engineering notes by DJ Sir
Types of SWM
Liquid wastes
Gaseous wastes
Solid wastes.
CLASSIFICATION OF SOLID WASTE:
Based on their sources of origin
Based on physical nature
SYSTEMS FOR SOLID WASTE MANAGEMENT:
METHODS FOR DISPOSAL OF THE SOLID WASTE:
OPEN DUMPS:
LANDFILLS:
Sanitary landfills
COMPOSTING
Different stages of composting
VERMICOMPOSTING:
Vermicomposting process:
Encapsulation:
Incineration
MANAGEMENT OF SOLID WASTE:
Refuse
Reuse
Recycle
Reduce
FACTORS AFFECTING SOLID WASTE MANAGEMENT:
File LinkedList.java Defines a doubly-l.pdfConint29
File: LinkedList.java
/**
* Defines a doubly-linked list class
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition
* @return the value stored at node first
* @throws NoSuchElementException
*/
public T getFirst() throws NoSuchElementException {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @pos.
Need Help with this Java Assignment. Program should be done in JAVA .pdfarchiesgallery
Need Help with this Java Assignment. Program should be done in JAVA please
Complete required scripts based on eclipse and troubleshoot the scripts until the tasks are done.
1. Implement a binary search tree (write the code for it), for a height of 2 or higher. Please show
the output if you can Thank you in advance!
Solution
I have compiled this code and checked for errors, worked fine.
Also after the code I have pasted the Output transcript to show what User Inputs I gave and what
all outputs I got.
// Java Program to Implement Binary Tree
import java.util.Scanner;
/* Define Class BinaryTreeNode */
class BinaryTreeNode
{
BinaryTreeNode left, right;
int data;
/* Constructor */
public BinaryTreeNode()
{
left = null;
right = null;
data = 0;
}
/* Constructor */
public BinaryTreeNode(int n)
{
left = null;
right = null;
data = n;
}
/* Function to set left node */
public void setLeft(BinaryTreeNode n)
{
left = n;
}
/* Function to set right node */
public void setRight(BinaryTreeNode n)
{
right = n;
}
/* Function to get left node */
public BinaryTreeNode getLeft()
{
return left;
}
/* Function to get right node */
public BinaryTreeNode getRight()
{
return right;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Define anothe Class Operations to perform required operationns on Binary Tree*/
class Operations
{
private BinaryTreeNode root;
/* Constructor */
public Operations()
{
root = null;
}
/* Function to check if tree is empty */
public boolean isEmpty()
{
return root == null;
}
/* Functions to insert data */
public void insert(int data)
{
root = insert(root, data);
}
/* Function to insert data recursively */
private BinaryTreeNode insert(BinaryTreeNode node, int data)
{
if (node == null)
node = new BinaryTreeNode(data);
else
{
if (node.getRight() == null)
node.right = insert(node.right, data);
else
node.left = insert(node.left, data);
}
return node;
}
/* Function to count number of nodes */
public int countNodes()
{
return countNodes(root);
}
/* Function to count number of nodes recursively */
private int countNodes(BinaryTreeNode r)
{
if (r == null)
return 0;
else
{
int l = 1;
l += countNodes(r.getLeft());
l += countNodes(r.getRight());
return l;
}
}
/* Function to search for an element */
public boolean search(int val)
{
return search(root, val);
}
/* Function to search for an element recursively */
private boolean search(BinaryTreeNode r, int val)
{
if (r.getData() == val)
return true;
if (r.getLeft() != null)
if (search(r.getLeft(), val))
return true;
if (r.getRight() != null)
if (search(r.getRight(), val))
return true;
return false;
}
/* Function for inorder traversal */
public void inorder()
{
inorder(root);
}
private void inorder(BinaryTreeNode r)
{
if (r != null)
{
inorder(r.getLeft());
System.out.print(r.getData() +\" \");
inorder(r.getRight());
}
}
/* Function for preorder traversal */
public void preorder()
{
preorder(root);
}
priva.
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
Write a Java Class to Implement a Generic Linked List
Your list must be implemented as a singly-linked list of generic nodes, where each Node object
has two instance variables: an object of the “type variable” class, and a pointer to the next node
on the list.
Your class will contain separate methods to handle each of the operations read from a data file
(see II., below)
Your class will also override toString() to return the objects on the list in the order in which they
occur.
Write a Test Class for Your LinkedList Class
Your main method will read list operation instructions from a data file, until end-of-file and call
the appropriate LinkedList method to execute each one.
After each operation is executed, print out the operation and the updated list.
The data file to be used is on the class web site and the operations are:
APPEND X - Append object X to the end of the list
ADD N X - Insert object X as the new Nth element in the list, increasing the size of the list by 1
E.g. Suppose the list is:
head -> 1 -> 2 -> 3 -> 4->null
After ADD 3 7 it would be:
head -> 1 -> 2 -> 7 -> 3 -> 4->null
DELETE N – Remove the Nth object from the list
SWAP M N - Interchange the positions of the Mth and Nth
objects on the list
For credit, the two nodes must actually \"trade places\" in the list, and not merely swap their data
values
REVERSE - Reverse the order of the objects on the list
This must be done by reversing the order of the nodes themselves, rather than by swapping the
data stored
To get credit for your reverse() method, it must use either one of these 2 algorithms:
For each node on the list except the current “head”
node, delete the node and insert it as the new head
Use your swap() method
6. CLEAR – Clear the list (make it empty)
No credit will be given for programs that use any additional data structures – either from the Java
API or programmer defined -, other than your own LinkedList class
txt file:
Solution
//Java Program to Implement Singly Linked List
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/* Class Node */
class Nodes
{
protected Object data;
protected Nodes next;
/* Constructor */
public Nodes()
{
next = null;
data = null;
}
/* Constructor */
public Nodes(Object d,Nodes n)
{
data = d;
next = n;
}
/* Function to set link to next Node */
public void setLink(Nodes n)
{
next = n;
}
/* Function to set data to current Node */
public void setData(Object d)
{
data = d;
}
/* Function to get link to next node */
public Nodes getLink()
{
return next;
}
/* Function to get data from current Node */
public Object getData()
{
return data;
}
}
/* Class linkedList */
class linkList
{
protected Nodes start;
protected Nodes end ;
public int size ;
/* Constructor */
public linkList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isEmpty()
{
return start == null;
}
/* Function to get size of list */
public int getSize()
{
return .
Java Programming- 1) Write a recursive method that finds and returns t.docxmichael1810
Java Programming:
1) Write a recursive method that finds and returns the sum of the elements in an int array. Also, write a program to test your method
** Please simple enough for a beginner to understand
Solution
/**
* @author
*
*/
public class RecusrsiveArraySum {
/**
* @param args
*/
public static void main(String[] args) {
int arr[] = { 3, 4, 6, 7 };
System.out
.println(\"Sum of array Elements: \" + sum(arr, arr.length - 1));
}
/**
* recursive sum of array elements
*
* @param array
* @param index
* @return
*/
public static int sum(int[] array, int index) {
// if array is empty
if (index < 0)
return 0;
if (index == 0) {
// when no index reaches first element
return array[0];
} else {
// adding array elements
return array[index] + sum(array, index - 1);
}
}
}
OUTPUT:
Sum of array Elements: 20
.
Using Array Approach, Linked List approach, and Delete Byte Approach.pdffms12345
Use the graph of the function f below to find the following. All local minimum values of f All
values at which f has a local minimum If there is more than one answer, separate them with
commas. All local minimum values of f All values at which f has a local minimum:
Solution
Dear student
Thank you for using Chegg
As per the given curve it is clear that the local minimum values of f are -3 & 0
Values of x when curve attain minimum values are x = -2,3.
Write a function which return a list of all of the n element subset .pdfhardjasonoco14599
Write a function which return a list of all of the n element subset of a given set
Implement in JAVA Question 3 Write a function that returns a list of all of the n-element subsets
of a given set. For example, if the given set is [1,2,3] and n is 2, then the returned list should
contain [1,2], [1,3], and [2,3]. The order of the elements is not important.
Solution
The program for this problem is as follows:
Comments are included in the program for explaining the steps.
A sample output is attached below the program.
package com.temp;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* Program to find sublists of a list.
* @author Rohit Phatak
*
*/
public class subset {
/**
* This list will contain the resultant sublists.
*/
static List list = new ArrayList<>();
public static void main(String arg[]){
/**
* Input a list comma separated.
*/
System.out.println(\"Enter a list : \");
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] sArr = s.split(\",\");
/**
* Input a value of n.
*/
System.out.println(\"Enter value of n : \");
Integer n = scanner.nextInt();
/**
* Check if value of n is greater than entered list.
*/
if(sArr.length < n){
System.out.println(\"Length of list is less than value of n\");
} else if(sArr.length > 0){
getSubsetList(sArr,n);
System.out.println(\"List is as :\");
/**
* Printing the sublists.
*/
for(String[] str : list){
String printVar = \"\";
for(String temps : str)
printVar+=temps+\",\";
System.out.println(\"[\"+printVar.substring(0, printVar.length()-1)+\"]\");
}
} else {
System.out.println(\"Please enter atleast one element:\");
}
scanner.close();
}
/**
* This method calls the recursive function which is used to obtain the sublists.
* @param sArr
* @param n
* @return
*/
public static List getSubsetList(String[] sArr,Integer n){
List lista = new ArrayList<>();
sublist(sArr, 0, n, new String[n]);
return lista;
}
/**
* This is a recursive function.
* This function will iterate over itself for finding the sublist.
*
* Parameters are as follows:
*
* @param arr -> List entered by the user.
* @param n -> Value of sublist entered by user.
* @param startPosition -> index to start creating the sublist.
* @param result -> resultant sublist
*/
public static void sublist(String[] arr, int startPosition, int n, String[] result){
/**
* Check for the value of n ==0.
* If n==0 break from the recursion.
*/
if (n == 0){
/**
* Add the sublist \'result\' in the list.
*/
list.add(result.clone());
return;
}
/**
* Iterate through for loop starting from startPosition till length of list minus entered value
n.
*/
for (int i = startPosition; i <= arr.length-n; i++){
/**
* Here result is a temporary sublist.
* This for loop adds an element to the temporary sublist in each iteration.
* The element is added from the complete list entered by user.
* Location of element is iTh index.
*/
result[result.length - n] = arr[i];
/**
* After adding the element to the temporary sublist, the sublist an.
In java , I want you to implement a Data Structure known as a Doubly.pdfaromalcom
In java , I want you to implement a Data Structure known as a Doubly-Ended-Queue. it is a
“fair” data structure in that it implements a FIFO (First In First Out ) behavior. As such, it is
often used to implement various wait lists in computer systems. For example, jobs waiting to use
the CPU, jobs waiting for a printer, jobs waiting to be placed into RAM for execution. In short,
whenever we want a fair strategy for waiting we use queues.
A DEQUE (Doubly-ended-queue) is a related data structure. Although similar to a Queue, it
differs in that it allows for insertions AND deletions from either end of the list (both the front
and the rear).
Your implementation MUST use a doubly-linked-list implementation. You may not use a static
array implementation.
Thus, a Deque is a List but it is one which only concerns itself with the first and last positions for
any insertion or deletion. The 6 operations supported are :
public void insertFront( int item ) - insert the given item (as a node) into the first position of the
Deque.
public void insertRear( int item ) - insert the given item (as a node) into the last position of the
Deque.
public int deleteFront( ) - delete and return the element stored in the first node of the Deque.
public int deletRear( ) – delete and return the element stored in the last node of the Deque.
public boolean isempty( ) - returns true if the Deque is currently empty or false if it is not.
public void printDeque( ) - print the integers from the list, one per line, from the first element
through to the last in order.
Classes
Your program must implement the following 3 classes. public class dequeDriver
This class will contain your program’s main method. It will need to declare a deque object and
process input as indicated below.
Your program should prompt the user for the path of an input file. It should open the file for
input and process it line by line. Each line of the input file will have one of the following forms.
PR
IF
IR
DF
DR
The meanings of each input is as follows:
PR - print the current contents of the deque from front to rear using the printDeque( ) method of
the deque object.
IF - insert the given int value into the front of the deque.
IR - insert the given int value into the rear of the deque.
DF - delete the front value from the deque.
DR – delete the rear element of the deque.
Below is an example input file that your program should be able to process.
PR
IF 4
IF 5
IF 6
IR 7
PR
DR
PR
DF
PR
The output for the input file shown above is :
EMPTY DEQUE
----- Front -----
6
5
4
7
----- Rear -----
----- Front -----
6
5
4
----- Rear -----
----- Front -----
5
4
----- Rear -----
public class dequeNode
This class will implement the linked nodes that will be used to implement the deque itself.
It should have the following protected data members.
protected dequeNode next; // next pointer to next node
protected dequeNode prev; // previous pointer to previous node
protected int val; // the integer value stored within the dequeNod.
Labprogram.java
LinkedList.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
*
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
*
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
public T getFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator != null) {
return iterator.data;
} else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
public void addIterator(T data) throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("addIterator Iterator is off end.");
}
if (iterator == last) {
addLast(data);
} else {
Node newNode = new Node(data);
Node next = iterator.next;
newNode.next = next;
newNode.prev = iterator;
iterator.next = newNode;
next.prev = newNode;
length++;
}
}
public void removeFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == first) {
iterator = null;
}
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == last) {
iterator = null;
}
last = last.prev;
last.next = null;
}
length--;
}
public void removeIterator() throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("Iterator is off the end opf the list.");
}
if (iterator .
C++ (pronounced "see plus plus") is a computer programming language based on C. It was created for writing programs for many different purposes. In the 1990s, C++ became one of the most used programming languages in the world.
The C++ programming language was developed by Bjarne Stroustrup at Bell Labs in the 1980s, and was originally named "C with classes". The language was planned as an improvement on the C programming language, adding features based on object-oriented programming. Step by step, a lot of advanced features were added to the language, like operator overloading, exception handling and templates.
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
package singlylinkedlist;
public class Node {
public String value;
public Node next;
public Node(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
SingleyLinkedList.java :
package singlylinkedlist;
import java.io.*;
import java.util.*;
/**
* Defines the interface for a singly-linked list.
*
*/
public interface SinglyLinkedList {
/**
* @return Reference to the first node. If the list is empty, this method
* returns null.
*/
public Node getFirst();
/**
* @return Reference to the last node . If the list is empty, this method
* returns null.
*/
public Node getLast();
/**
* @return Number of nodes in the list
*/
public int size();
/**
* @return true if the list has no nodes; false otherwise
*/
public boolean isEmpty();
/**
* Removes all nodes in the list.
*/
public void clear();
/**
* Inserts a new node with the given value after cursor.
*
* @param cursor
* The node to insert after. Set this to null to insert value as
the
* new first Node.
* @param value
* The value to insert
* @return a reference to the newly inserted Node
*/
public Node insert(Node cursor, String value);
/**
* Inserts a new node with the given value at the "end" of the list.
*
* @param value
* @return a reference to the newly inserted Node
*/
public Node append(String value);
/**
* Removes the node after the specified Node (cursor) from the list.
*
* @param cursor
* A reference to the Node to remove.
*/
public void removeAfter(Node cursor);
/**
* Returns a reference to the first Node containing the key, starting from
the
* given Node.
*
* @param start
* @param key
* @return a reference to the first Node containing the key
*/
public Node find(Node start, String key);
/**
* Prints the values of all the items in a list
*/
public void printWholeList();
}
SinglyLinkedTester.java:
package sbccunittest;
import static java.lang.Math.*;
import static java.lang.System.*;
import static org.apache.commons.lang3.StringUtils.*;
import static org.junit.Assert.*;
import static sbcc.Core.*;
import java.io.*;
import java.lang.reflect.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
import org.apache.commons.lang3.*;
import org.junit.*;
import org.w3c.dom.ranges.*;
import sbcc.*;
import singlylinkedlist.*;
/**
* 09/16/2021
*
* @author sstrenn
*
*/
public class SinglyLinkedListTester {
public static String newline = System.getProperty("line.separator");
public static int totalScore = 0;
public static int extraCredit = 0;
public static boolean isZeroScore = false;
public static String scorePreamble = "";
@BeforeClass
public static void beforeTesting() {
totalScore = 0;
extraCredit = 0;
}
@AfterClass
public static void afterTesting() {
if (isZeroScore) {
totalScore = 0;
extraCredit = 0;
}
println(scorePreamble + "Estimated score (w/o late penalties, etc.) is:
" + totalScore + " out of 25.");
// If the project follows the naming convention, save the results in a
folder on
// the desktop. (Alex Kohanim)
try {
String directory =
substri.
Please help solve this in C++ So the program is working fin.pdfankit11134
Please help solve this in C++. So the program is working fine but when submitting it, it gives me a
code -11, and I believe the problem is that after inserting the numbers it removes them one by one
until the last in the list, and when it tries to remove the last number in the list that is when it
counters the problem. Below is the full code but you just need to change something in the
SortedNumberList.h file under the bool remove function.
4.18 LAB: Sorted number list implementation with linked lists Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking on
the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables: - a double data value, - a pointer to the next node, and - a pointer to the
previous node. Each member variable is protected. So code outside of the class must use the
provided getter and setter member functions to get or set a member variable. Node.h is read only,
since no changes are required. Step 2: Implement the Insert() member function A class for a
sorted, doubly-linked list is declared in SortedNumberList.h. Implement the SortedNumberList
class's Insert() member function. The function must create a new node with the parameter value,
then insert the node into the proper sorted position in the linked list. Ex: Suppose a
SortedNumberList's current list is 2347.2586, then Insert(33.5) is called. A new node with data
value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's sorted order
and yielding: 2335.547.2586Step 3: Test in develop mode Code in main() takes a space-
separated list of numbers and inserts each into a SortedNumberList. The list is displayed after
each insertion. Ex: If input is 77154263.5 then output is: List after inserting 77 : 77 List after
inserting 15 : 1577 List after inserting -42 : -421577 List after inserting 63.5: -421563.577 Try
various program inputs, ensuring that each outputs a sorted list. Step 4: Implement the Remove()
member function Implement the SortedNumberList class's Remove(0 member function. The
function takes a parameter for the number to be removed from the list. If the number does not
exist in the list, the list is not changed and false is returned. Otherwise, the first instance of the
number is removed from the list and true is returned. Uncomment the commented-out part in
main() that reads a second input line and removes numbers from the list. Test in develop mode to
ensure that insertion and removal both work properly, then submit code for grading. Ex: If input is
841972841961 then output is: List after inserting 84: 84 List after inserting 72 : 7284 List after
inserting 19: 1972 84 List after inserting 61: 1961 : 72 8 List after removing 19: 6172 84 List after
removing 84: 6172Current file: main.cpp - // Insert each value and show the sorted List's contents
after each insertion sortedNumberList list; for (auto term : terms) { doubl.
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
Solid waste management & Types of Basic civil Engineering notes by DJ Sir
Types of SWM
Liquid wastes
Gaseous wastes
Solid wastes.
CLASSIFICATION OF SOLID WASTE:
Based on their sources of origin
Based on physical nature
SYSTEMS FOR SOLID WASTE MANAGEMENT:
METHODS FOR DISPOSAL OF THE SOLID WASTE:
OPEN DUMPS:
LANDFILLS:
Sanitary landfills
COMPOSTING
Different stages of composting
VERMICOMPOSTING:
Vermicomposting process:
Encapsulation:
Incineration
MANAGEMENT OF SOLID WASTE:
Refuse
Reuse
Recycle
Reduce
FACTORS AFFECTING SOLID WASTE MANAGEMENT:
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity Green house effect & Hydrological cycle
Types of Ecosystem
(1) Natural Ecosystem
(2) Artificial Ecosystem
component of ecosystem
Biotic Components
Abiotic Components
Producers
Consumers
Decomposers
Functions of Ecosystem
Types of Biodiversity
Genetic Biodiversity
Species Biodiversity
Ecological Biodiversity
Importance of Biodiversity
Hydrological Cycle
Green House Effect
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
1. Merit-Quality-Excellence
Sukkur IBA University
Data Structures (Fall 2023)
LAB No: 02
Instructor: Marina Gul
Objective of Lab No. 2:
After performing lab2, students will be able to:
o More on Array
o Implementation of Linked list
Practice 01
We have already covered an array. Perform following task on an array,
a) Input size of an array
b) Define and create array with the input size on random value
c) Display the defined array
d) Implement insert, delete and search operation (Binary)
import java.util.Random;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Take input the size of an array
Scanner sc = new Scanner(System.in); // Create a Scanner object
System.out.println("Enter the size of an Array");
int size= sc.nextInt(); // Read user input
//create array with the input size on random value
Random rd = new Random(); // creating Random object
rd.setSeed(System.currentTimeMillis()); // use current time as a seed
// fill the data array with pseudo-random numbers from 0 to 99,
inclusive
int[] arr = new int[size];
for (int i = 0; i < arr.length; i++)
arr[i] = rd.nextInt(100); // storing random integers in an array
//Display the defined array
System.out.println(Arrays.toString(arr));
//delete an element from array
arr = MyArray.removeTheElement(arr, 2);
System.out.println(Arrays.toString(arr));
2. }
}
/** Program showing some array uses. */
class MyArray{
// Function to remove the element
public static int[] removeTheElement(int[] arr, int index)
{
// If the array is empty or the index is not in array range
// return the original array
if (arr == null || index < 0
|| index >= arr.length) {
return arr;
}
int i=0;
//start form the index till end of array
for (i = index; i< arr.length-1; i++)
arr[i]=arr[i+1];
// for last index
arr[i]=0;
// return the resultant array
return arr;
}
// Returns index of x if it is present in arr[].
public static int binarySearch(int arr[], int x)
{
int l = 0, r = arr.length - 1;
while (l <= r) {
int m = l + (r - l) / 2;
// Check if x is present at mid
if (arr[m] == x)
return m;
// If x greater, ignore left half
if (arr[m] < x)
l = m + 1;
// If x is smaller, ignore right half
else
r = m - 1;
}
// If we reach here, then element was
// not present
return -1;
}
}
3. Practice 02
We have already covered Linked List. Some of the basic operation of linked list are following
a) Create linked list
b) Implementation of Insert, show, isEmpty and delete operation
class Node{
int data;
Node next;
//Constructor
Node(int data)
{
this.data=data;
this.next=null;
}
}
class LinkedList{
Node head;
void addLast(int data)
{
Node node=new Node(data);
node.data=data;
node.next=null;
if(head==null)
head=node;
else{
Node n=head;
while(n.next!=null)
n=n.next;
n.next=node;
}
}
void show() {
Node = head;
while (node.next != null){
System.out.print(node.data + " ");
node = node.next;
}
System.out.print(node.data + " ");
}
void addStart(int data)
{
Node =new Node(data);
node.data=data;
//node.next=null;
node.next=head;
head=node;
}
void addMiddle(int index,int data)
6. Exercise
Arrays
1. Create a file named NLArray.java and design following functions or performing NLP.
- String [] wordTokenize (String fileName) Read any text file and return list of words
from that file. (Ignore . , : and all these types operators)
- String[] extractEmail (String fileName) Read any text file and return all emails from
and file
Note: Read about Natural Language Processing (NLP), Word Tokenizing, Stop Words,
Information Extraction/Retrieval for Knowledge.
2. Design following methods in above same class NLArray.java for Image Cropping.
- void extractBoundaries (int arr[][]) This function should extract boundaries and
print from arr (Boundaries include 1st
row, 1st
col, last row, last col).
- void cropCenterPart (int arr[][]) This function should extract center part and print
from arr, center part includes everything except Boundaries (Boundaries include 1st
row,
1st
col, last row, last col).
3. Design following methods in above same class NLArray.java in order to determining N
consecutive same values
boolean NConRep (int arr[][]) This function would return True if N consecutive values are
same otherwise false. Check examples:
2 1 3 5
22 22 22 22
12 41 88 53
57 8 74 4
N is 4 so matrix is 4x4 and in 4 consecutive values are same so it should return True.
Linked List
4. Implement a function to search for a specific element in a linked list.
5. Write a function to find the length of a linked list.
6. In this task you will write a program that implements a variant of a linked list. This variant has
a dummy node pointed to by the head link as shown in the following figure:
7. Linked list with a dummy first node:
This trick will allow your code to be a little simpler, not requiring a special case for add or remove
operations. Your constructor method will be:
public LinkedList(){
head = new Node(null);
size = 0;
}
You need to write a class called LinkedList that implements the following List interface:
// a list interface
public interface List {
public boolean isEmpty();
// returns true if the list is empty, false otherwise
public int size();
// returns the number of items in the list
public void add(Object item);
// adds an item to the list
// item is added at the end of the list
public void add(int index, Object item);
// adds an item to the list at the given index
// item is added at the given index;
// the indices start from 1.
public void remove(int index);
// removes the item from the list that has the given index
public void remove(Object item);
// removes an item from the list
// removes the first item in the list whose equal method matches
// that of the given item
public List duplicate();
// creates a duplicate of the list
// returns a copy of the linked list
public List duplicateReversed();
8. // creates a duplicate of the list with the nodes in reverse order
// returns a copy of the linked list with the nodes in reverse order
}
In addition to the interface, your LinkedList class needs to implement a toString() method that
prints the list in the format
[ size: the_size_of_the_list - item1, item2, .... ]
Note: Your Node class should be an inner class within the LinkedList class. Make sure your
class implements the interface as specified, i.e. your class should begin with public class
LinkedList implements List.