I need to create a linked list that contains a fixed arraylist. Each new entry is added to array list. If the arraylist is full, create a new arraylist and add to the linklist. In java please.
In: Computer Science
You are provided with a partial implementation of a templated singly-linked list in LinkedList.h, with some missing functionality. It contains a templated Node class and a templated LinkedList class. Do not modify the class definitions.
The linked list class contains the following methods:
• LinkedList – Constructor of a linked list with a head pointing to null (implemented).
• ~LinkedList – Destructor of a linked list.
• deleteFromHead – Removes and returns content of the first node of the list. (If the list is empty, does nothing.)
• deleteFromTail – Removes and returns content of last node of the list. (If the list is empty, does nothing.)
• deleteNode – Removes node with provided data from the list.
• InsertToHead – Inserts node with provided data at the head (implemented).
• InsertToTail – Inserts node with provided data at the tail. • getSize – Returns the number of nodes in the linked list.
• print - Prints the linked list (implemented).
Notice that while the declaration and implementation of classes are typically split between .cpp and .h files, some compilers cannot handle templates in separate files, which is why we include both the declaration and implementation in a single .h file. The main.cpp file consists of sample test code for each of the tasks below. Your code, which should be added to the provided LinkedList.h will be compiled and run with variations of this file. Submit your modified LinkedList.h file only
LinkedList.h:
#ifndef LinkedList_h
#define LinkedList_h
#include <iostream>
using namespace std;
template <class T = int>
class Node {
public:
Node(); // default constructor
Node(const T& data, Node<T>* next = nullptr); // donstructor
T data; // node data
Node<T>* next; // node next pointer
};
template <class T = int>
class LinkedList {
public:
LinkedList(); // constructor
~LinkedList(); // destructor
T deleteFromHead(); // removes and returns content of head
T deleteFromTail() // removes and returns content of tail
void deleteNode(T data) // removes node with specified data
void InsertToHead(T data); // insert node with data at the head
void InsertToTail(T data); // insert node with data at the tail
int getSize(); // returns size of linked list
void print(); // prints linked list
private:
Node<T>* head; // head of linked list
};
/******* From here down is the content of the LinkedList.cpp file: ***********************/
/* Implementation of Node */
// default constructor
template<class T>
Node<T>::Node()
{
}
// constructor
template<class T>
Node<T>::Node(const T& data, Node<T>* next)
{
this->data = data;
this->next = next;
}
/* Implementation of linked list */
// constructor
template <class T>
LinkedList<T>::LinkedList()
{
head = nullptr;
}
// destructor
template <class T>
LinkedList<T>::~LinkedList()
{
/*** to be implemented ***/
}
template <class T>
T LinkedList<T>::deleteFromHead()
{
/*** to be implemented ***/
}
template <class T>
T LinkedList<T>::deleteFromTail()
{
/*** to be implemented ***/
}
template <class T>
void LinkedList<T>::deleteNode(T data)
{
/*** to be implemented ***/
}
template <class T>
void LinkedList<T>::InsertToHead(T data)
{
Node<T> * newNode = new Node<T>(data, nullptr);
if (head == nullptr)
head = newNode;
else
{
newNode->next = head;
head = newNode;
}
}
template <class T>
void LinkedList<T>::InsertToTail(T data)
{
/*** to be implemented ***/
}
template <class T>
int LinkedList<T>::getSize()
{
/*** to be implemented ***/
}
template <class T>
void LinkedList<T>::print()
{
if (head == nullptr)
{
cout << "Linked list is empty" << endl;;
return;
}
cout << head->data << " ";
if (head->next == nullptr)
{
cout << endl;
return;
}
Node<T>* currNode = head->next;
Node<T>* prevNode = head;
while (currNode->next != nullptr)
{
cout << currNode->data << " ";
prevNode = currNode;
currNode = currNode->next;
}
cout << currNode->data << endl;
return;
}
#endif /* LinkedList_h */In: Computer Science
In short, you’re going to implement a linked-list class for storing integers, using a provided main program to help you interact and test your work. You’ll want to build the linked-list class function by function, working in “Develop” mode to test out each function you write.
main.cpp is a read only file
linkedlist.h is the file to work on.
main.cpp
#include
#include
#include "linkedlist.h"
using namespace std;
int main()
{
linkedlist LL;
string cmd;
int value, key;
//
// user can enter commands to manipulate the LL:
//
// p w => push w onto the end
// i x y => insert x after y (y must exist in the list)
// r z => remove the first instance of z
// o => output the list
// q => quit
//
//cout << "Enter a command> ";
cin >> cmd;
while (cmd != "q")
{
if (cmd == "p")
{
// push:
cin >> value;
LL.push_back(value);
}
else if (cmd == "i")
{
// insert:
cin >> value;
cin >> key;
LL.insert(value, key);
}
else if (cmd == "r")
{
// remove:
cin >> value;
LL.remove(value);
}
else if (cmd == "o")
{
// output:
LL.output();
}
else
{
cout << "**Invalid command, try p, i, r, o or q" <<
endl;
cout << endl;
}
//cout << "Enter a command> ";
cin >> cmd;
}
return 0;
}
linkedlist.h
/*linkedlist.h*/
#pragma once
#include <iostream>
using namespace std;
class linkedlist
{
private:
struct NODE
{
int Data;
struct NODE* Next;
};
struct NODE* Head; // first node in list (or nullptr)
struct NODE* Tail; // last node in list (or nullptr)
int Size; // # of elements (i.e. nodes) in list
public:
//
// default constructor
//
// Creates an empty list.
//
linkedlist()
{
Head = nullptr;
Tail = nullptr;
Size = 0;
}
//
// size
//
// Returns the # of elements in the list.
//
int size()
{
return Size;
}
//
// push_back
//
// Pushes value onto the end of the list.
//
void push_back(int value)
{
struct NODE* newNode = new struct NODE();
newNode->Data = value;
newNode->Next = nullptr;
//
// TODO: a new node containing the value was created
// above. Add this new node to the end of the list.
//
//
// HINT #2: don't forget to increment size
//
}
//
// insert
//
// Inserts the given value in the list *after* the key. If
// the key cannot be found, nothing happens; if the key
occurs
// multiple times, value will be inserted after the first
// instance.
//
void insert(int value, int key)
{
// allocate a new node to hold the value:
struct NODE* newNode = new struct NODE();
newNode->Data = value;
newNode->Next = nullptr;
//
// TODO: a new node containing the value was created
// above. Insert this new node after the node containing
// the given key (assume the key appears only once).
// If the key cannot be found (or the list is empty), do
// nothing and just return (or delete newNode and return).
//
t.
//
// HINT #2: don't forget to increment size
//
}
//
// remove
//
// Removes the first instance of value from the list; if
// the value cannot be found, nothing happens.
//
void remove(int value)
{
//
// TODO: remove the first node that contains value; if value
// is not found, do nothing. You'll need to search the list
// for the value, and then unlink that node from the list.
// Don't worry about freeing the memory, you can ignore that
// for now (or use delete ptrToNode; if you want to free).
//
//
// HINT #2: don't forget to decrement size
//
}
//
// output
//
// Outputs the size, followed by the elements one by one on
// the same line.
//
void output()
{
cout << "Size: " << Size << endl;
cout << "Elements: ";
//
// TODO: output elements with a space after each one
// (including a space after last element). Output all
// on the same line, save the end-of-line for after
// the traversal loop is over.
//
.
//
cout << endl;
}
};
In: Computer Science
The following SinglyLinkedList class is available:
class SinglyLinkedList:
class _Node:
"""Lightweight, nonpublic class for storing a singly linked node."""
__slots__ = 'element', 'next' # streamline memory usage
def __init__(self, element, next): # initialize node's fields
self.element = element # reference to user's element
self.next = next # reference to next node
def __init__(self): # initialize list's fields
self._head = None # head references to None
def printList(self, label):
print(label, end=' ')
curr = self._head
while curr != None:
print(curr.element, end=" -> ")
curr = curr.next
print("/")
#########################################################
# Only this method is required for your solution
def computeStats(self):
# Your code goes here
#########################################################
def main():
# Create a list object for testing purpose
sList = SinglyLinkedList()
# Create list 2 -> 4 -> -1 -> 8 -> -5
sList._head = sList._Node(2, sList._Node(4, sList._Node(-1, sList._Node(8, sList._Node(-5, None)))))
sList.printList("before:")
# Call computeStats method
sList.computeStats()
# And see if it worked!
sList.printList("after :")
if __name__=="__main__":
main()
Assume you have a singly-linked list of integers, some positive and some negative. Write a Python method that traverses this list to calculate both the average and the count (ie, number) of the odd values only. Once calculated, add the average to a new node at the front of the list, and the count to a new node at the end of the list. You may assume that the list will always contain at least one odd value.
Your method will be have the following method signature:
def computeStats(self):
You may use only the SinglyLinkedList class; no other methods (like size(), etc) are available.
For example, if the list initially contains:
2 → 4 → -1 → 8 → -5
the resulting list will contain:
-3.0 → 2 → 4 → -1 → 8 → -5 → 2
In: Computer Science
Do students reduce study time in classes where they achieve a higher midterm score? In a Journal of Economic Education article (Winter 2005), Gregory Krohn and Catherine O’Connor studied student effort and performance in a class over a semester. In an intermediate macroeconomics course, they found that “students respond to higher midterm scores by reducing the number of hours they subsequently allocate to studying for the course.” Suppose that a random sample of n = 8 students who performed well on the midterm exam was taken and weekly study times before and after the exam were compared. The resulting data are given in Table 10.6. Assume that the population of all possible paired differences is normally distributed. Table 10.6 Weekly Study Time Data for Students Who Perform Well on the MidTerm Students 1 2 3 4 5 6 7 8 Before 15 19 12 17 16 15 11 16 After 11 18 9 10 8 9 11 10 Paired T-Test and CI: Study Before, Study After Paired T for Study Before - Study After N Mean StDev SE Mean StudyBefore 8 15.1250 2.5877 .9149 StudyAfter 8 10.7500 3.1053 1.0979 Difference 8 4.37500 2.87539 1.01660 95% CI for mean difference: (1.97112, 6.77888) T-Test of mean difference = 0 (vs not = 0): T-Value = 4.30, P-Value = .0036 (a) Set up the null and alternative hypotheses to test whether there is a difference in the true mean study time before and after the midterm exam. H0: µd = versus Ha: µd ≠ (b) Above we present the MINITAB output for the paired differences test. Use the output and critical values to test the hypotheses at the .10, .05, and .01 level of significance. Has the true mean study time changed? (Round your answer to 2 decimal places.) t = We have evidence. (c) Use the p-value to test the hypotheses at the .10, .05, and .01 level of significance. How much evidence is there against the null hypothesis? There is against the null hypothesis. 02_16_2018_QC_CS-118501
In: Statistics and Probability
One may organize cost data and their distribution among
stakeholders in various ways to assess overall project viability,
and cost distribution to analyse the project’s attractiveness to
various stakeholders. One approach to organizing such data is to
identify the various categories for the project inputs in column
(1), then show the total value of each input in column (2) and use
subsequent columns to show the various stakeholders’ contribution.
Similar to the case we did in class, consider the following project
designed to train 100 low-income workers for a year.
Costs
The sponsoring NGO spends GHS 200,000 on Rental of Premises a year,
after Students and their Families have contributed labour to
prepare the project site, thus lowering the rental costs by GHS
50,000. In addition, Students and their Families pay for the
services of a part-time worker, valued at GHS 25,000 a year. The
NGO pays GHS 225,000 as salaries of two full-time skilled staff.
Further, a Private firm donates computers valued at GHS 20,000. The
cost of material and supplies are an additional GHS 20,000, of
which the sponsoring NGO bears GHS 8,000 and the rest are donated
by a private entity. The sponsoring NGO bears half the costs of
utilities; Government bears the other half. Total utilities are
estimated at GHS 50,000. For the period they are in training,
Students incur GHS 2,000 each in lost income and Government loses
GHS 200 per student.
Gains of the Project
When students complete, they are expected to earn GHS 100 each per
month more than they would otherwise have earned for 5 years and
Government will earn GHS 30 extra from each of them as tax The
opportunity cost of this project to Students and Government is 24%
p.a.
Questions
i. Present the data in a tabular form for ease of analysis showing
benefits and costs to each stakeholder and on Society. Consider all
private sector contributions to the project as one stakeholder,
called PRIVATE.
ii. Calculate the proportion of total cost being borne by each
stakeholder.
iii. Do you advise that this Project be undertaken? Explain.
In: Accounting
Match the scenario with the most appropriate statistical test to use
Hint: Some statistical tests will match with more than one scenario. Pay attention to the symbols used to give you information about whether the mean and standard deviation come from populations or samples.
A. Z-test
B. One sample t-test
C. Independent Sample t-test
D. related samples t-test
|
In: Statistics and Probability
We wish to determine if two instructors teaching the same introductory course have significantly different “DF rates” (defined as the proportion of students who receive a course grade of D or F among all students who complete the course).Each instructor teaches 60 students. Among the first instructor’s students, 21 receive a D or F. Among the second instructor’s students, 16 receive a D or F. Assume these can be treated as independent simple random samples from their respective populations.
Use this sample data to test the claim H0:(p1−p2)=0H0:(p1−p2)=0 against HA:(p1−p2)≠0HA:(p1−p2)≠0, using a significance level of 5%.
The value of the test statistic is z=
A large pharmaceutical company advertises that its newly-deleveloped drug is “more effective” at curing a certain disease than the existing drug of its leading competitor. To test this claim, we can compare the proportions of patients who are cured of the disease, depending on which drug they are using for treatment.In a simple random sample of 80 patients being treated with the newly-developed drug, 20 patients were successfully cured of the disease. In an independent simple random sample of 80 patients being treated with the existing drug, 12 patients were successfully cured of the disease.
Use the sample data to test the hypotheses H0:(p1−p2)=0H0:(p1−p2)=0 against HA:(p1−p2)>0HA:(p1−p2)>0, using a significance level of 5%.
The value of the test statistic is z =
In a certain population, it is believed that the proportion of men having red/green color blindness is higher than the proportion of women having red/green color blindness. A hypothesis test can be used to test this claim.
Independent simple random samples of 950 men and 2500 women are tested. Among the men in the sample, 81 have red/green color blindness. Among the women in the sample, 9 have red/green color blindness.The value of the test statistic is z=
In: Statistics and Probability
5. (a)A sample of 12 of bags of Calbie Chips were weighed (to the nearest gram), and listed, here as follows.
219, 226, 217, 224, 223, 216, 221, 228, 215, 229, 225, 229 Find a 95% confidence interval for the mean mass of bags of Calbie Chips.
[9 marks]
(b) Professor GeniusAtCalculus has two lecture sections (A and B) of the same 4th year Advanced Calculus (AMA 4301) course in Semester 2. She wants to investigate whether section A students maybe ”smarter” than section B students by comparing their perfor- mances in the midterm test. A random sample of 12 students were taken from section A, with mean midterm test score of 78.8 and standard deviation 8.5; and a random sample of 9 students were taken from section B, with mean midterm test score of 86 and standard deviation 9.3. Assume the population standard deviations of midterm test scores for both sections are the same. Construct the 90% confidence interval for the difference in midterm test scores of the two sections. Based on the sample midterm test scores from the two sections, can Professor GeniusAtCalculus conclude that there is any evidence that one section of students are ”smarter” than the other section? Justify your conclusions.
[8 marks]
(c) The COVID-19 (coronavirus) mortality rate of a country is defined as the ratio of the number of deaths due to COVID-19 divided by the number of (confirmed) cases of COVID-19 in that country. Suppose we want to investigate if there is any difference between the COVID-19 mortality rate in the US and the UK. On April 18, 2020, out of a sample of 671,493 cases of COVID-19 in the US, there was 33,288 deaths; and out of a sample of 109,754 cases of COVID-19 in the UK, there was 14,606 deaths. What is the 92% confidence interval in the true difference in the mortality rates between the two countries? What can you conclude about the difference in the mortality rates between the US and the UK? Justify your conclusions. [8 marks]
In: Statistics and Probability
CVP—sensitivity analysis. Joan’s Beauty College is considering introducing a new nail design seminar to run on an annual basis with the following price and cost characteristics:
|
Tuition |
$405.00 per Student |
|
Variable Costs (polish, supplies, etc.) |
$185.00 per Student |
|
Fixed Costs (advertising, instructor’s salary, insurance, etc.) |
$29,480 per Year |
Required:
2a. What enrollment enables Joan’s Beauty College to break even?
Break even = 29,490/(405-185)= 134
134 enrollment enable’s Joan’s Beauty College to break even.
2b. How many students will enable Joan’s Beauty College to make an operating profit of $35,750 for the year?
(29,480+35,750)/(405-185)= 296.5
It will take 297 students to enroll for Joan’s Beauty College to make a operating profit for the desired income of $35,750.
2c. Assume that the projected enrollment for the year is 350 students for each of the following situations:
(1) What will be the operating profit for 350 students?
((405-185) x 350) – 29,480 = $47,520
The operating profit for 350 students will be $47,520.
(2) What would be the operating profit and changecompared to the results from c(1)if the tuition per student (that is, sales price) (show amount change & %)
(i).decreased by 10 percent?
47,520 – (405*350*.10) = 47520 – 14,175 = $33,345 operating profit
Operating profit decrease % = (47,520 – 33,345)/ 47,520 = 29.83%
Operating profit change in amount is $14,175.
(ii). Increased by 20 percent?
47,520 + (405*350*.20) = 47,520 + 28,350 = $75,870 operating profit
Operating profit increase % = 28,350 / 47,520 = 59.66%
Operating profit change in amount is $28,350.
(3) What would be the operating profit and changecompared to the results from c(1)if variable costs per student (show amount change & %)
(i) increased by 10 percent?
(ii) Decreased by 20 percent?
(4) Suppose that fixed costs for the year are 10 percent lower than projected, whereas variable costs per student are 20 percent higher than projected. What would be the operating profit(loss)for the year?
In: Accounting