Update the following C code and write the function :
void sln_stutter(sln_list* li);
that modifies the list li so that it each element is duplicated. For example the list with elements [1,2,3] would after this function call become the list [1,1,2,2,3,3].
#include <stdlib.h>
#include <stdio.h>
struct sln_node {
struct sln_node* next;
int key;
};
struct sln_list {
struct sln_node* head;
};
typedef struct sln_node sln_node;
typedef struct sln_list sln_list;
static sln_node* freelist = NULL;
/* Internal bookkeeping functions for the free list of nodes. */
sln_node* sln_allocate_node() {
sln_node* n;
if(freelist == NULL) {
freelist = malloc(sizeof(sln_node));
freelist->next = NULL;
}
n = freelist;
freelist = n->next;
n->next = NULL;
return n;
}
void sln_release_node(sln_node* n) {
n->next = freelist;
freelist = n;
}
void sln_release_freelist() {
sln_node* n;
while(freelist != NULL) {
n = freelist;
freelist = freelist->next;
free(n);
}
}
/* Create a new singly-linked list. */
sln_list* sln_create() {
sln_list* list = malloc(sizeof(sln_list));
list->head = NULL;
return list;
}
/* Release the list and all its nodes. */
void sln_release(sln_list* list) {
sln_node* n = list->head;
sln_node* m;
while(n != NULL) {
m = n->next;
sln_release_node(n);
n = m;
}
free(list);
}
/* Insert a new element to the list. */
void sln_insert(sln_list* list, int key) {
sln_node* n = sln_allocate_node();
n->key = key;
n->next = list->head;
list->head = n;
}
/* Check if the list contains the given element. Returns 1 or 0. */
int sln_contains(sln_list* list, int key) {
sln_node* n = list->head;
while(n != NULL && n->key != key) {
n = n->next;
}
return (n == NULL)? 0: 1;
}
/* Remove the first occurrence of the given element from the list.
Returns 1 if an element was removed, 0 otherwise. */
int sln_remove(sln_list* list, int key) {
sln_node* n;
sln_node* m;
n = list->head;
if(n == NULL) { return 0; }
if(n->key == key) {
list->head = n->next;
sln_release_node(n);
return 1;
}
while(n->next != NULL && n->next->key != key) {
n = n->next;
}
if(n->next != NULL) {
m = n->next;
n->next = m->next;
sln_release_node(m);
return 1;
}
return 0;
}
In: Computer Science
I have a list of things for review in C programming, could you please give me an example and a brief explanation for each question... Thank you very much
In: Computer Science
Cyanide ion, CN-, is important in metal plating industries as well as in leaching matals from ores because it keeps metals dissolved under conditions where they would otherwise form solids (precipitate) and settle out of solution. It is important to maintain pH>10.5 in these solutions to avoid forming toxic hydrogen cyanide gas. If a solution is prepared by dissolving 10-2M NaCN in water, will the pH be in the region where the solution is safe? What is {HCN} in the solution? The pKa of HCN is 9.24.
In: Chemistry
in free radical polymerization, wastage reaction are due to
In: Chemistry
1) Describe the various shapes of synovial joints (e.g. hinge, condyloid, ball and socket, etc.)
2) What types of movements can occur at synovial joints (e.g. gliding, angular, etc.)?
In: Anatomy and Physiology
In: Computer Science
Suppose we want to make a 10 item queue starting from location
x4000. In class, we discussed using a HEAD and a TAIL pointer to
keep track of the beginning and end of the queue. In fact, we
suggested that the HEAD pointer could point to the first element
that we would remove from the queue and the TAIL pointer could
point the last element that we have added the queue. It turns out
that our suggestion does not work.
Part a) What is wrong with our suggestion? (Hint: how do we check
if the queue is full? How do we check if it is empty?)
Part b) What simple change could be made to our queue to resolve
this problem?
Part c) Using your correction, write a few instructions that check
if the queue is full. Use R3 for the HEAD pointer and R4 for the
TAIL pointer.
Part d) Using your correction, write a few instructions that check
if the queue is empty. Again, using R3 for the HEAD pointer and R4
for the TAIL pointer.
In: Computer Science
Balancing Redox Equations in Acidic or Basic Solutions
In addition to mass balance, oxidation-reduction reactions must be balanced such that the number of electrons lost in the oxidation equals the number of electrons gained in the reduction. This balancing can be done by two methods. The oxidation number method balances the net increase in oxidation of the substance oxidized with the net decrease in the oxidation number of the substance reduced. The half-reaction method balances the electrons lost in the oxidation half-reaction with the electrons gained in the reduction half-reaction. In both methods
H2O(l),OH?(aq), and H+ (aq) may be added to complete the mass balance. Which substances are used depends on the reaction conditions.
Acidic solution
In acidic solution, bromate ion can be used to react with a number of metal ions. One such reaction is
BrO3?(aq)+Sn2+(aq)?Br?(aq)+Sn4+(aq)
Since this reaction takes place in acidic solution,
H2O(l)andH+(aq) will be involved in the reaction. Places for these species are indicated by the blanks in the following restatement of the equation:
BrO3?(aq)+Sn2+(aq)+ ____ ?Br?(aq)+Sn4+(aq)+ ___
Part A
What are the coefficients of the six species in the balanced equation above? Remember to include coefficients for
H2O(l)andH+(aq)
in the appropriate blanks.
Enter the equation coefficients in order separated by commas (e.g., 2,2,1,4,4,3).
Basic solution
Potassium permanganate,
KMnO4, is a powerful oxidizing agent. The products of a given redox reaction with the permanganate ion depend on the reaction conditions used. In basic solution, the following equation represents the reaction of this ion with a solution containing sodium sulfite:
MnO4?(aq)+SO32?(aq)?MnO2(s)+SO42?(aq)Since this reaction takes place in basic solution,H2O(l)andOH?(aq)
will be shown in the reaction. Places for these species are indicated by the blanks in the following restatement of the equation:
MnO4?(aq)+SO32?(aq)+ ____?MnO2(s)+SO42?(aq)+ ___
Part B
What are the coefficients of the six species in the balanced equation above? Remember to include coefficients for
H2O(l)andOH? (aq) in the blanks where appropriate.
Enter the equation coefficients in order separated by commas (e.g., 2,2,1,4,4,3).
In: Chemistry
In: Operations Management
A rocket is launched at an angle of 50.0° above the horizontal with an initial speed of 102 m/s. The rocket moves for 3.00 s along its initial line of motion with an acceleration of 30.0 m/s2. At this time, its engines fail and the rocket proceeds to move as a projectile.
(a) Find the maximum altitude reached by the rocket.
m
(b) Find its total time of flight.
s
(c) Find its horizontal range.
In: Physics
The two-dimensional arrays list1 and list2 are identical if they have the same contents. Write a method that returns true if they are identical and false if they are not. Use the following header: public static boolean equals(int [][] list1, int [][] list2)
Write a test program that prompts the user to enter two 3 x 3 arrays of integers and displays whether the two are identical.
Enter list1:
Enter list2:
The two arrays are identical or The two arrays are not identical
In: Computer Science
A cart is attached to a hanging mass by a string that passes over a pulley. a) Draw free-body diagrams for the cart and the hanging mass (Clearly label all forces present and indicate their relative magnitudes) when the cart is moving:(i) on a horizontal track.(ii) up a track inclined at an angle .b) When the cart moves on an incline at constant speed, it is in equilibrium; i.e., the net force on it is zero. Does it require more, less, or the same tension in the string to pull the cart up the track at constant speed or down the track at constant speed? Explain your answer.c)Derive an equation for the work done by friction when the cart is moving up the track at constant speed. Show your work.
In: Physics
Here is a picture of a Binary Search Tree.
First, construct the Binary Search Tree using the following
BinaryNode as we discussed in class.
public class BinaryNode {
private int value;
private BinaryNode leftChild;
private BinaryNode rightChild;
public BinaryNode(int value) {
this.value = value;
leftChild = null;
rightChild = null;
}
public BinaryNode(int value, BinaryNode leftChild, BinaryNode rightChild)
{
this.value = value;
this.leftChild = leftChild;
this.rightChild = rightChild;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public BinaryNode getLeftChild() {
return leftChild;
}
public void setLeftChild(BinaryNode leftChild) {
this.leftChild = leftChild;
}
public BinaryNode getRightChild() {
return rightChild;
}
public void setRightChild(BinaryNode rightChild) {
this.rightChild = rightChild;
}
@Override
public String toString() {
return "BinaryNode: " +
"value=" + value;
}
}
|
Second, print the nodes in level order, that is, the root node first, then the children of the root node, then the grand-children, etc. It is recommended that you accomplish this by using a queue to store the nodes, printing the first nodes that have been added to the queue.
Your program should print the following when it runs.
42 27 50 21 38 60 33 41 72 |
Submit the file LevelOrder.java when done.
In: Computer Science
Question 5: Describe why pulling a heavy object seems more hazardous than pushing it.
Question 6: What is the difference between local and whole body strength?
In: Physics
Use the given degree of confidence and sample data to construct a confidence interval for the population proportion p.
A survey of 865 voters in one state reveals that 408 favor approval of an issue before the legislature. Construct the 95% confidence interval for the true proportion of all voters in the state who favor approval.
In: Math