The code for the implementation of the `convert` function in Python is:
```python
def convert(lst):
a_list = []
b_list = []
for pair in lst:
a_list.append(pair[0])
b_list.append(pair[1])
return (a_list, b_list)
```
Using this function, convert([(1, 2), (3, 4), (5, 6)]) will evaluate to ([1, 3, 5], [2, 4, 6]).
To write a function named "convert" that takes a list of pairs and converts it into a pair of lists, preserving the order of the elements, you can follow these steps:
1. Define the function "convert" with a parameter "lst" representing the input list of pairs.
2. Initialize two empty lists, "a_list" and "b_list", to store the first and second elements of each pair respectively.
3. Iterate through the input list "lst".
4. For each pair in "lst", append the first element of the pair to "a_list" and the second element to "b_list".
5. Return the tuple containing "a_list" and "b_list".
Learn more about the convert function: https://brainly.in/question/52066151
#SPJ11
gradual process by which machines replaced hand tools
The Industrial Revolution refers to the gradual process by which machines replaced hand tools in the early 1800s.
What is Industrial Revolution?
The Industrial Revolution was a period of significant change from the mid-18th century to the mid-19th century, characterized by the transition from hand-based to machine-based manufacturing, increased agricultural productivity, and new developments in transportation.
The growth of iron and textile industries marked the beginning of this era, which spread throughout Britain and eventually to other countries in Europe and North America. It brought about massive changes in the way goods were produced, leading to higher levels of efficiency and a shift from a agrarian to an industrialized economy, transforming the lives of millions of people and setting the stage for the modern era.
To learn more about Industrial Revolution, visit: https://brainly.com/question/29547311
#SPJ4
What type of switches shut off the flow of electricity immediately when they sense that the electrical current might no longer be flowing along the correct path?.
Circuit Breakers or Fuses: A circuit breaker is a switching device in a circuit that interrupts an irregular flow of current.
It uses an internal system of bounds or compact air to sense any changes in the current flow. It will 'break' the circuit open and cut the flow of current.
What component controls the flow of electricity by turning it on and off?
The breakers or switches handle the electricity. If too many devices on the same circuit are employed at the same time, an overload may occur. If there is an overload of electricity in any of the courses of the home, the breaker will open the course to stop the flow of electricity.
What switches are operated by humans to control power flow to outputs?
Hand switches are actuated by human touch. Limit controls are actuated by machine motion.
To learn more about Circuit Breakers, refer
https://brainly.com/question/28021068
#SPJ4
Airports use moving walkways to increase the distance people
have to walk to facilitate their movements.
Answer choices
True
False
False. Airports use moving walkways to decrease the distance people have to walk and enhance their convenience and efficiency while moving within the airport.
The statement is incorrect. Airports utilize moving walkways, also known as travelators or moving sidewalks, to reduce the distance people need to walk and facilitate their movements. Moving walkways are designed to enhance convenience and efficiency by allowing individuals to cover greater distances within the airport more quickly and with less physical effort. They are especially useful in large airports where terminals and gates can be far apart. By providing a moving surface, airports aim to streamline passenger flow and minimize the time and effort required for individuals to traverse long distances within the airport premises. Moving walkways offer a time-saving benefit and contribute to the overall ease of travel for passengers, improving their experience and reducing fatigue associated with walking long distances.
Learn more about distances : brainly.com/question/31713805
#SPJ11
The rectifier is used to
Answer:
A rectifier is an electrical device used to convert alternating current to direct current.
Explanation:
Hope this helps! Shalom
The source voltages vg1and vg2 in the circuit in (Figure 1) are 12 V and 3 V, respectively.
Calculate iΔ
Calculate vo
Find the total power developed in the circuit.
Find the total power absorbed in the circuit.
The power developed in the circuit is 56.25 W and the power absorbed by the circuit is also 56.25 W. So, there is no net power transfer in the circuit. Hence, this circuit is a balanced circuit.
The given circuit in the Figure 1 is shown below:Figure 1The voltage v in the middle is common between the two sources, but they have different polarities. We apply KVL around the closed loop of the circuit containing the sources and the resistor to determine the current, iΔ. -12 + 6iΔ - 2(iΔ+4) + 3 = 0 Simplifying the above equation, 4iΔ = 15iΔ = 15/4 = 3.75 A The current iΔ is flowing in the direction shown in the Figure 1. We can now use Ohm's law to find the voltage across the resistor. vo = iΔ × 4 = 3.75 × 4 = 15 V Total power developed in the circuit can be found by multiplying the total current in the circuit by the voltage v. PT = (12 - 3) × (3.75 + 2) = 56.25 W where the currents passing through vg1 and vg2 are (12 - v) and v/2 respectively.The power absorbed by the circuit can be found using the current iΔ: PA = (iΔ)² × 4 = (3.75)² × 4 = 56.25 W
To know more about balanced circuit, visit:
https://brainly.com/question/31555724
#SPJ11
what are the besl measures used for data variation or dispersion
Answer:
STANDARD DAVIATION OR SD
Explanation:
BECAUSE it is commonly in measuring of dispersion and it also the most roubst measure of variability
The no-slip condition is:________
a. Valid only for liquids
b. It only applies to compressible gases
c. An experimental observation that the velocity of a fluid in contact with a solid surface is equal to the velocity of the surface.
d. Indicates that two solids in contact will not slip if the joining force is large.
e. Useful only for very low density geses.
Answer:
The correct answer is option (c) An experimental observation that the velocity of a fluid in contact with a solid surface is equal to the velocity of the surface.
Explanation
Solution:
When a fluid is in proximity to the boundary the solid and the velocities are the same or uniform for the fluid and the surface, no slip condition does not exist.
However, because the no-slip meets the expectations for gas and liquids, this condition no way connected in this case of two solid in proximity.
hence, the other options are wrong here.
The solid cylindrical bar shown is subjected to a bending force F = 55kN, an axial load P = 8 kN, and a torsional load T = 30 kN-mm. The bar is made of AISI 1060 CD steel (Sy = 280 MPa, Sut = 330 MPa). Find the factor of safety based on Maximum Distortion Energy Theory.
The factor of Safety by Maximum Distortion Energy Theory is given as: N = 6.04
What is Maximum Distortion Energy Theory?
According to this idea, failure by yielding happens when the distortion energy per unit volume in a condition of combined stress equals that associated with yielding in a basic tension test at any location in the body.
What is the calculation for the above value?
Note that we are given the following:
A solid Steel bar subjected to a bending force of F = 55kN
Torsional load T = 30 kN-mm; and
Yield Strength (sy) = 280Mpa
Sut = 330 Mpa
The formula for Normal Stress is given as:
\(\alpha _{x}\) = [UP/πd²] + [ (32* f * L)/πd³]
= [(4 * 8 * 10³)/π * (0.02)²] + [(32 * 55 *10³ * 0.1)/ π * (0.02)³]
= 25.46 + 7.003
\(\alpha _{x}\)= 32.5 Mpa
Tyz = (16T)/πd³
= (16 * 30)/ π * (0.02)³
= 19.098
Tyz = 19.098
Following from the above, sate of stress, we have:
α₁ = αₓ = 32.46 Mpa; and
α₂ = Tyz = 19.098 Mpa;
α₃ = -Tyz = -p19.098 Mpa;
Utilizing the formula given by the Maximum Distortion Energy Theory:
α₁² + α₂² + α₃² - (α₁α₂ + α₂α₃ + α₃α₁)
= Sy²/N²
→ 32.46² + 19.098² + 19.098² - ( 32.46* 19.098 - 19.098² -32.46 * 19.098)
= 280/N²
N = 6.04
Learn more about Maximum Distortion Energy Theory at:
https://brainly.com/question/22435706
#SPJ1
QUESTION ONE Write short answers on the following questions: i. Rainfall depth over a watershed is monitored through six number of well distributed rain gauges. Gauged data are given below: Rain Gauge Number 1 2 3 4 5 6 Rainfall Depth (mm) 470 465 435 525 480 510 Area of Thiessen Polygon (x104 m²) 95 100 98 80 85 92 The Thiessen mean value (in mm, up to one decimal place) of the rainfall is
Answer:
identify function of the system unit and its components
The shape of the wood beam is a rectangle. In a paragraph explain the tradeoffs an engineer would make in selecting a wood with a rectangle shape versus manufactured beams with other stronger but lighter weight shapes.
Answer:
Wood is heavy
Explanation:
5. What is the biggest danger when using
electric drills?
O A. Using the wrong size bit for the hole
required can ruin the drill.
O B. The bit could get caught and throw the
user.
O C. The bit coming loose in the drill can
cause a loss of torque.
O D. Static electricity can build up and
deliver an electric shock to the user.
Answer:
Static electricity can build up and
deliver an electric shock to the user drilling with an electric drill or any drill can create static electricity but with electric drills the static electricity can react with the drills power supply creating a short circuit proceeding to shock you which is why electric drills have rubber grips around them to INSULATE the shock if It does happen (also that's why the drills mostly are made up of non conductive materials.)
*WELDING*
What size arc gap is suggested with a 5/32" (4.0mm) diameter electrode?
Solution :
The correct size of the arc of a welding process depends upon the application and the electrode. As a rule, the arc length should not be more than a diameter of the core of the electrode.
As for the electrode of diameter size of 5/32" or 4 mm, the arc length should be more than its core diameter. Also for 5/32 " diameter electrode, the welding time for the one electrode must be one minute as well as the length of the weld be the same as the length of the electrode consumed.
A reservoir rock system located between a depth of 2153m and a depth of
2383m , as the pressure at these depths is 18.200 MPa , 19.643 MPa
respectively the thickness of oil zone 103m, if the density of water is 1060 kg/m3
Determine the oil and gas density. what is the pressure at the depth of 2200m ?
what is the depth at which the pressure is 1900 MPa? Determine the gas-oil and
oil- water contact depth.
What is "Engineering"?
A yeast culture weighing 2 grams is removed from a refrigerator unit and is expected to grow at the rate of W'(t)=0.3e02 grams per hour at a higher controlled temperature. How much will the weight of the culture increase during the first 8 hours of growth? How much will the weight of the culture increase from the end of the 8th hour to the end of the 16th hour of growth?
The weight increase during the first 8 hours is approximately grams. (Type an integer or decimal rounded to three decimal places as needed.)
The weight of the culture will increase approximately 0.859 grams during the first 8 hours of growth.
To find the weight increase during the first 8 hours of growth, we can integrate the rate of growth function W'(t) over the interval [0, 8].
Given that W'(t) = \(0.3e^0.2\)grams per hour, the weight increase during the first 8 hours is:
\(∫[0, 8] W'(t) dt = ∫[0, 8] 0.3e^0.2 dt\)
Integrating this function, we have:
\(∫[0, 8] 0.3e^0.2 dt = 0.3∫[0, 8] e^0.2 dt\)
Integrating \(e^0.2\) with respect to t gives:
\(0.3 * (1/0.2) * e^0.2 ∣[0, 8] = 0.3 * (5 * e^0.2 - 1)\) ≈ 0.859 grams
Therefore, the weight of the culture will increase approximately 0.859 grams during the first 8 hours of growth.
Learn more about integrate here-
https://brainly.com/question/31954835
#SPJ11
6-16. use d-type flip-flops and gates to design a counter with the following repeated binary sequence: 0, 2, 1, 3, 4, 6, 5, 7
The truth table for the circuit is given below:
The truth table for the combinational circuit:A B C Q2 Q1 Q0
0 0 0 0 0 1
0 0 1 0 1 0
0 1 0 1 0 1
0 1 1 1 1 1
1 0 0 0 1 0
1 0 1 1 0 1
1 1 0 1 1 0
1 1 1 1 1 1
Initially, Q2, Q1 and Q0 are all set to 0 which signifies the first row of the flip-flops.
In order to load values into these individual flip-flops for each clock pulse, one must refer to the next rows in the sequence. As an example, if a current state of 001 is detected from the flip-flops, then the combinational circuit is signaled to output 010 immediately before loading this value on the subsequent clock pulse.
To produce the desired result, one would need the assistance of the following logic gates:
A NOT gate assigned to each input bit (A, B, and C)
Two separate AND gates allocated towards both output bits (Q2, Q1, and Q0)
An additional pair of OR gates molded to combine the AND gate's output for modulating each respective output bit.
The counter is composed of three D-type flip-flops and a combinational circuit consisting of NOT, AND, and OR gates.
The combinational circuit generates the next state of the flip-flops based on their current state and the desired sequence of values. On each clock pulse, the current state of the flip-flops is replaced with the next state generated by the combinational circuit, resulting in the desired repeated binary sequence.
Read more about truth tables here:
https://brainly.com/question/28605215
#SPJ1
tech a says that semi-floating wrist pins can be pressed into the rods. tech b says that a rod heater can be used to install semi-floating wrist pins. who is correct?
The correct answer is both the tech are right that a rod heater can be used to install semi-floating wrist pins and semi-floating wrist pins can be pressed into the rods.
After some kind of friction secures the pin to the connecting, the piston can freely pivot inside the bosses of the piston pin. The most common method of attaching the semi-floating wrist pins to the rod is by press-fitting. The little end of the connecting rod is heated, which expands the metal and the diameter of the hole.If you're using high-level forced induction, nitrous oxide injection, high rpm or heavy sustained loading on your performance engine, upgraded semi-floating wrist pins represent the insurance deal of the century. Wall thickness is a critical factor based on application.
To learn more about semi-floating wrist pins click the link below:
brainly.com/question/24887891
#SPJ4
cargo ship refrigeration units are usually sized with very little reserve capacity.T/F
The given statement is False, cargo ship refrigeration units are typically sized with a significant reserve capacity.
Cargo ship refrigeration units are designed to maintain the proper temperature and humidity levels for transporting perishable goods. To ensure the safe transportation of the cargo, refrigeration units are usually sized with a significant reserve capacity. This reserve capacity allows the refrigeration system to handle unexpected conditions such as ambient temperature fluctuations, door openings, and variations in cargo load. It provides a buffer to accommodate any potential increase in cooling demand and helps prevent temperature deviations that could compromise the quality and safety of the cargo. Additionally, the reserve capacity also accounts for maintenance and servicing requirements, ensuring that the refrigeration system can continue operating effectively even during routine maintenance activities. Overall, the inclusion of reserve capacity in cargo ship refrigeration units is a standard practice to ensure reliable and efficient operation throughout the transportation process.
Learn more about cargo ship refrigeration here;
https://brainly.com/question/28971161
#SPJ11
why should you disconnect the leads prior to changing scales when measuring current
You should disconnect the leads prior to changing scales when measuring current to prevent damage to the measuring instrument and ensure accurate readings.
Here's a step-by-step explanation:
1. Disconnect the leads: This is done to avoid any potential harm to the device or its circuits due to a sudden change in the scale while a current is still flowing through the meter.
2. Change the scale: Safely change the scale on the measuring instrument to the appropriate setting for the current you wish to measure.
3. Reconnect the leads: After adjusting the scale, reconnect the leads to the appropriate terminals and continue with your measurement.
By following these steps, you ensure the safety and accuracy of your current measurements.
Electrical energy is converted to heat energy. To ensure the temperature of the wire does not increase, switch off between readings and keep the current as low as possible.
Learn more about the current: https://brainly.com/question/24858512
#SPJ11
There are two potential fall hazards in this image. What are they?
Answer:
Lack of fall protection and Scaffold is overloaded
Write a program to play the Card Guessing Game. Your program must give the user the following choices: - Guess only the face value of the card. - Guess only the suit of the card. - Guess both the face value and the suit of the card. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck.
how am I going to do this, I have a friend that might be able to help I will check
HEY CAN ANYONE PLS SOLVE THIS MACHINE PROBLEM SHOW WORK!!!!!
Based on information that a crowbar exerts 755N of force to open a 250 cm heavy door. It took 5.00 seconds to open the door and 40.0 watts of power was used on the crowbar.
What is the work done by the crowbar?Work= Force x Distance x cos(theta)
How to calculate theta:
Theta corresponds to the angle formed between the force and the displacement. As the crowbar is used to pry open the door, we assume that the force is applied perpendicular to the door, so: theta= 90º and cos(theta)= 0
Therefore, the answer to letter a will be:
Work = 755N x 250cm x 0 = 0 Joules
B) The work done on the crowbar will be equal and opposite in sign to the work done on the crowbar, so that will also be 0 Joules.
Therefore, in letter C, we conclude that the efficiency of the crowbar corresponds to the ratio between the output and input of work, which are 0 Joules, so the efficiency will be 0%, demonstrating that the crowbar was not effective to open the door.
Find more about force of work on:
https://brainly.com/question/25573309
#SPJ1
Design a decimal arithmetic unit with two selection variables, V1, and Vo, and two BCD digits, A and B. The unit should have four arithmetic operations which depend on the values of the selection variables as shown below. V1=0011, V0=0101 and output functions are as follows;
1- A+9's complement of B
2- A+B
3- A+10's complement of B
4- A+1 (add 1 to A)
(You can see question number 3 in the attached file)
What signal propagation phenomena causes the diffusion, or the reflection in multiple different directions, of a signal?
In the radio communication system, multipath is the propagation phenomenon that causes diffusion or reflection in multiple different directions of a signal.
Multipath is a propagation mechanism that impacts the propagation of signals in radio communication. Multipath results in the transmission of data to the receiving antenna by two or more paths. Diffusion and reflection are the causes that create multiple paths for the signal to be delivered.
Diffraction occurs when a signal bends around sharp corners; while reflection occurs when a signal impinges on a smooth object. When a signal is received through more than one path because of the diffraction or reflection, it creates phase shifting and interference of the signal.
You can learn more about signal propagation at
https://brainly.com/question/14452898
#SPJ4
A moist rock mass is characterized by the following parameters: joint water pressure is nill; point load index is 3MPa; Joint spacing is 0.5m; and RQD is 55%; Joint condition is open joints filled with 5mm gouge. Classify the rock mass according to RMR method.
The RMR value is 413.15, which indicates that the rock mass is of excellent quality.
What is RMR method?The most important geologic criteria are combined by RMR, which depicts them as a single, comprehensive indicator of rock mass quality.
Based on the given parameters, we can use the Rock Mass Rating (RMR) method to classify the rock mass.
The RMR value is given by the formula:
RMR = 70Q + 10G + 5F + 8L + 7S - 3W
Using the given parameters, we can calculate the RMR value as follows:
Q = 10 x \((RQD/10)^{1/2\) x (Jn + Ja + Jw + Jr + Jsr)
Where Jn, Ja, Jw, Jr, and Jsr are the joint sets orientations, number, water pressure, roughness, and spacing rating, respectively.
Since we do not have information about the joint orientations and roughness, we can assume that they have a neutral effect on the RMR value, which means that Jn=Ja=Jr=1 and Jw=Jsr=0.5.
Therefore,
Q = 10 x\((55/10)^{1/2\) x (1 + 1 + 0.5 + 1 + 0.5) = 57.45
G = 0 (since joint water pressure is nil)
F = 5 (since the joint condition is open joints filled with gouge)
L = 8 - 2.6 x log10(0.5) = 5.44
S = 7 (since the joint condition is filled with 5mm gouge)
W = 0 (since joint water pressure is nil)
Thus, RMR = 7057.45 + 100 + 55 + 85.44 + 77 - 30 = 413.15
For more details regarding RMR method, visit:
https://brainly.com/question/30039261
#SPJ9
Which of the following is an example of seeking accreditation?
A. An aspiring architect applies to the top school for architecture in her area.
B.A new engineering school voluntarily submits its program of study to peer review.
C.A graduating engineering student prepares to take the Fundamentals of Engineering exam.
D. An architectural engineer submits the schematic for a new building’s HVAC system to another engineer for approval.
B
Explanation:
Think this has to do with educational facility vs. person seeking accreditation in say AIA (American Institute of Architects)
A certain piece of property is assessed at $150,000. If the tax rate is $2.50 per $100, what is the tax on this property?
Answer:
The tax on this property is \(3750\) dollars
Explanation:
Given
Tax on per $100 is $2.50
Tax on every $1 is \(\frac{2.5}{100} = 0.025\) dollars
Tax on property of value $150,000 is
\(150,000 * 0.025 = 3750\) dollars
The tax on this property is \(3750\) dollars
Assume the address of name is 10 and the address of x is 14. (that is, name is stored in memory location 10, and x is stored in memory location 14.) problems 10—13 refer to the following statements:
int name, x=20.5;
int *a = &x;
...
name = *a;
I understand you need an explanation regarding the given code snippet that involves pointers, memory addresses, and variable assignments. Here's a concise overview of the code:
First, we have two integer variables, 'name' and 'x'. 'x' is assigned a value of 20.5, but since it's an integer, the decimal part will be truncated, and 'x' will store the value 20. The memory addresses for 'name' and 'x' are 10 and 14, respectively.
Next, we have a pointer 'a' of integer type. The pointer 'a' is assigned the address of 'x', which is 14. Therefore, 'a' points to the memory location of 'x'.
Finally, the value stored in the memory location pointed to by 'a' is assigned to 'name'. Since 'a' points to the memory location of 'x', the value of 'x' (20) is assigned to 'name'.
In summary, the code creates two integer variables 'name' and 'x', with 'x' storing the value 20. An integer pointer 'a' is assigned the address of 'x'. Then, the value stored in the memory location pointed to by 'a' (which is the value of 'x') is assigned to 'name'. After the execution of this code, both 'name' and 'x' will have the value 20.
Learn more about variable here
https://brainly.com/question/28248724
#SPJ11
The given code extracts two variables, namely, "name" and "x," along with their corresponding addresses of 10 and 14.
What next does the code do?Next, a reference variable named "a" is declared and initialized with the memory location of "x" (represented by &x). In conclusion, by using the pointer "a" (*a), the value of "x" is allocated to the variable "name". Consequently, "name" will have a value of 20.
The code initializes "x" with the value 20.5 and creates a pointer "a" pointing to "x". The value of "x" is then assigned to "name" using the dereference operator, so "name" will also have the value 20.5.
Read more about programs here:
https://brainly.com/question/26134656
#SPJ4
#3. describe the first case where the power of synthesis was used to solve design problems.
#4. describe the second case where the power of synthesis was used to solve design problems.
The first case where the power of synthesis was applied was in Chile, where they had to put 100 families in houses around 40 m². The second case where the power of synthesis used to solve a design problem is when they were making a building.
What is the power of synthesis?The power of synthesis is based on the belief that, while each individual insight, function adds value.
When we work together to inform and inspire the company's priorities, our value grows exponentially.
Thus, the first case where the power of synthesis was applied was in Chile, where they had to put 100 families in houses around 40 m². The second case where the power of synthesis used to solve a design problem is when they were making a building.
Learn more about power of synthesis
https://brainly.com/question/25885135
#SPJ1
Create a static method that: is called remove All • returns nothing • takes two parameters: an ArrayList of Strings called wordList, and a String called targetWord This method should go through every element of wordList and remove every instance of targetWord from the ArrayList. Create a static method that: • is called appendPossum • returns an ArrayList • takes one parameter: an ArrayList of Integers . This method should: Create a new ArrayList of Integers Add only the positive Integers to the new ArrayList • Sum the positive Integers in the new ArrayList and add the Sum as the last element For example, if the incoming ArrayList contains the Integers (4.-6,3,-8,0,4.3), the ArrayList that gets returned should be (4.3,4,3,14), with 14 being the sum of (4.3,4,3). The original ArrayList should remain unchanged.
The answer provided below has been developed in a clear step by step manner.
Answer:
#include "linked_list.h"
#include <iostream>
using namespace std;
Linked_List::Linked_List(){
length = 0;
head = nullptr;
}
int Linked_List::get_length(){
return this->length;
}
unsigned int Linked_List::push_front(int new_val){
length ++;
Node *new_node = new Node(new_val, head);
head = new_node;
return length;
}
unsigned int Linked_List::push_back(int new_val){
length ++;
if (head == nullptr){ //if it's empty
head = new Node(new_val, nullptr);
}
else{
Node *temp = this-> head; //start from head
while (temp->next != nullptr){
temp = temp->next; //scrolling till the very end
}
//inserting it at the end:
Node *new_node = new Node(new_val, temp->next);
temp-> next = new_node;
}
return length;
}
unsigned int Linked_List::insert(int new_val, unsigned int index){
length++;
Node *temp = new Node(new_val, NULL);
if (index == 0){
temp->next = this->head;
head = temp;
return length;
}
else{
temp = this-> head;
//temp -> val = new_val;
int check = index-1;
for (int i = 0; i< check; i++){
temp = temp->next;
}
Node *new_node = new Node(new_val, temp->next);
temp-> next = new_node;
}
return length;
}
void Linked_List::print(){
Node *temp = this->head;
while (temp != nullptr){
cout << temp->val << " ";
temp = temp->next;
}
cout << endl;
}
void Linked_List::clear(){
delete head;
}
void Linked_List::delete_all_nodes(){
length = 0;
Node* next = nullptr;
Node* temp = head;
while (temp != nullptr){
next = temp->next;
free(temp);
temp = next;
}
head = nullptr;
}
Linked_List::Linked_List(const Linked_List& old_list){
cout << "Invoked the copy constructor!" << endl;
this-> length = old_list.length;
this-> head = nullptr;
Node *temp = old_list.head;
while(temp != nullptr){
Node *test = new Node(temp->val, temp->next);
if (this->head == nullptr){
this->head = test;
}
temp = temp->next;
}
}
Linked_List& Linked_List::operator=(const Linked_List& old_list){
cout << "Invoked the overloaded assignment operator" << endl;
this-> length = old_list.length;
this-> head = nullptr;
Node *temp = old_list.head;
while(temp != nullptr){
Node *test = new Node(temp->val, temp->next);
if (this->head == nullptr){
this->head = test;
}
temp = temp->next;
}
return *this;
}
void Linked_List::check_for_prime(){
int counter = 0;
bool flag = true;
Node *temp = this->head;
while (temp != nullptr){
// this assignment requires that a negative number is never considered to be prime. 0 and 1 are also not considered as prime numbers
if (temp->val > 1){
for (int i = 2; i <= temp->val/2; i++){
if (temp->val % i == 0){ // here we check if there is such number that fully divides our value
flag = false;
break;
}
}
if (flag == true){
counter++;
}
else{ flag = true; }
}
temp = temp->next;
}
cout << "You have " << counter << " prime number(s) in your list. (that's the total number of prime numbers) " << endl;
}
/*
merge_sort(head){
1) check if length <= 1 if so return
2) split unsorted list in half
3) first = merge_sort(first half)
4) second = merge_sort(second half)
5) merge(first, second)
}
*/
Node* merge_sort(Node* head){
Node *temp = head;
int length = 0;
while (temp != nullptr){
temp = temp -> next;
length ++;
}
if (length <= 1){
return head;
}
temp = head;
for (int i = 0; i< ((length-1)/2); i++){
temp = temp -> next;
}
Node *second = temp-> next;
temp-> next = NULL;
temp = head;
head = merge_sort(head);
second = merge_sort(second);
return merge(head, second);
}
Node* merge(Node* first, Node* second){
Node* result = nullptr;
if (first == nullptr){
return second;
}
else if (second == nullptr){
return first;
}
if (first->val <= second->val) {
result = first;
result->next = merge(first->next, second);
}
else{
result = second;
result->next = merge(first, second->next);
}
return result;
}
void Linked_List::sort_ascending(){
if (head == nullptr){
return;
}
head = merge_sort(head);
}
void swap_nodes(Node** head, Node* currX, Node* currY, Node* prevY){
// make 'currY' as new head
*head = currY;
prevY->next = currX;
Node* temp = currX->next;
currX->next = currY->next;
currY->next = temp;
}
Node* selection_sort(Node* head){
// if there is only a single node
if (head->next == NULL){
return head;
}
Node* min = head;
Node* beforeMin = NULL;
Node *temp = head;
while (temp->next != nullptr){
if (temp->next->val >= min->val) {
min = temp->next;
beforeMin = temp;
}
temp = temp->next;
}
if (min != head){
swap_nodes(&head, head, min, beforeMin);
}
// recursively sort the remaining list
head->next = selection_sort(head->next);
return head;
}
void Linked_List::sort_descending(){
if (head == nullptr){
return;
}
head = selection_sort(head);
}
void Linked_List::list_revese(){
Node *temp = head->next;
Node *prev = head;
Node *next = NULL;
head->next = NULL;
while (temp != nullptr){
next = temp->next;
temp->next = prev;
prev = temp;
temp = next;
}
head = prev;
}
To know more about Array List visit:
https://brainly.com/question/17265929
#SPJ4