THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED
HELP FIXING THIS CODE?
THIS IS THE PROBLEM
Write a program that allows the user to enter two positive integers and outputs their sum. Sounds
simple? Here\'s the catch: The numbers may be any size! They may be way too large to store in a
single variable. You may not assume any particular maximum number of digits.
HERE IS THE CODE
#include
#include
struct node /* Linked list node*/
{
int data;
struct node* next;
};
struct node *newNode(int data) /* Function to create a new node with giving the data*/
{
struct node *new_node = (struct node *) malloc(sizeof(struct node));
new_node->data = data;
new_node->next = NULL;
return new_node;
}
void push(struct node** head_ref, int new_data) /* Function to insert a node at the beginning of
the Doubly Linked List*/
{
struct node* new_node = newNode(new_data); /*allocate a node*/
new_node->next = (*head_ref); /* link the old list off to the new node*/
(*head_ref) = new_node; /*move the head to point to the new node*/
}
/* Adding the contents of two linked lists and return the head node of resultant list*/
struct node* addTwoLists (struct node* first, struct node* second)
{
struct node* res = NULL; /* res is head node of the resultant list*/
struct node *temp, *prev = NULL;
int carry = 0, sum;
while (first != NULL || second != NULL) /*while both the lists exists*/
{
/* Calculate value of next digit in resultant list.
// The next digit is sum of following things
// (i) Carry
// (ii) Next digit of first list (if there is a next digit)
// (ii) Next digit of second list (if there is a next digit)*/
sum = carry + (first? first->data: 0) + (second? second->data: 0);
carry = (sum >= 10)? 1 : 0; /* update carry for next calulation*/
sum = sum % 10; /*update sum if it is greater than 10*/
temp = newNode(sum); /*Create a new node with sum as data*/
if(res == NULL) /*if this is the first node then set it as head of the resultant list*/
res = temp;
else /* If this is not the first node then connect it to the rest.*/
prev->next = temp;
prev = temp; /* Set prev for next insertion*/
if (first) first = first->next; /* Move first pointers to next node*/
if (second) second = second->next; /*Move second pointer to the next node*/
}
if (carry > 0)
temp->next = newNode(carry);
return res; /* return head of the resultant list*/
}
void printList(struct node *node) /* function to print a linked list*/
{
while(node != NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
printf(\"\ \");
}
int main(void) /* program to test above function*/
{
struct node* res = NULL;
struct node* first = NULL;
struct node* second = NULL;
printf(\"Enter first positive integer: \");
scanf(\"%d\",&first);
printList(first);
printf(\"Enter second positive integer: \");
scanf(\"%d\",&second);
printList(second);
/*Add the two lists and see result*/
res = addTwoLists(first, second);
printf(\"Sum is: %d\");
printList(res);
return 0;
}
Solution
#include
#include
typedef struct Node
{
int da.
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
C++
Write a method Node *Node::reverse() which reverses a list.
Solution
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Function to reverse the linked list */
static void reverse(struct node** head_ref)
{
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head_ref = prev;
}
/* Function to push a node */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
/* Driver program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
push(&head, 20);
push(&head, 4);
push(&head, 15);
push(&head, 85);
printf(\"Given linked list\ \");
printList(head);
reverse(&head);
printf(\"\ Reversed Linked list \ \");
printList(head);
getchar();
}.
1
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Takes head pointer of the linked list and index
as arguments and return data at index*/
int GetNth(struct node* head, int index)
{
struct node* current = head;
int count = 0; /* the index of the node we\'re currently
looking at */
while (current != NULL)
{
if (count == index)
return(current->data);
count++;
current = current->next;
}
/* if we get to this line, the caller was asking
for a non-existent element so we assert fail */
assert(0);
}
/* Drier program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
/* Use push() to construct below list
1->12->1->4->1 */
push(&head, 1);
push(&head, 4);
push(&head, 1);
push(&head, 12);
push(&head, 1);
/* Check the count function */
printf(\"Element at index 3 is %d\", GetNth(head, 3));
getchar();
}
2
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Takes head pointer of the linked list and index
as arguments and return data at index*/
int GetNth(struct node* head, int index)
{
struct node* current = head;
int count = 0; /* the index of the node we\'re currently
looking at */
while (current != NULL)
{
if (count == index)
return(current->data);
count++;
current = current->next;
}
/* if we get to this line, the caller was asking
for a non-existent element so we assert fail */
assert(0);
}
/* Drier program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
/* Use push() to construct below list
1->12->1->4->1 */
push(&head, 1);
push(&head, 4);
push(&head, 1);
push(&head, 12);
push(&head, 1);
/* Check the count function */
printf(\"Element at index 3 is %d\", GetNth(head, 3));
getchar();
}
Solution
1
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node*.
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
Use C++ Write a function to merge two doubly linked lists. The input.pdfshalins6
Use C++ Write a function to merge two doubly linked lists. The input lists have their elements in
sorted order, from lowest to highest. The output list should also be sorted from lowest to highest.
Your algorithm should run in linear time on the length of the output list. Provide an algorithm for
your function Implement and show some samples of your running function
Solution
/* This is a C++ program to merge two sorted linked lists and produce a list in a
Sorted order */
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* This function is used to pull off the front node of the source and put it in destnation */
void letusMoveNode(struct node** destRef, struct node** sourceRef);
/* This is a function used for performing merging of two linked lists.It takes two lists sorted in
increasing order, and splices
their nodes together to make one big sorted list which
is returned. */
struct node* letssortlists(struct node* a, struct node* b)
{
/* Let us first have dummyone first node to hang the result on */
struct node dummyone;
/*next the tail points to the last result node */
struct node* tail = &dummyone;
/* As a result, tail->next is the place to add new nodes
to the result. */
dummyone.next = NULL;
while (1)
{
if (a == NULL)
{
/*we will check that if either list runs out, use the
other list */
tail->next = b;
break;
}
else if (b == NULL)
{
tail->next = a;
break;
}
if (a->data <= b->data)
letusMoveNode(&(tail->next), &a);
else
letusMoveNode(&(tail->next), &b);
tail = tail->next;
}
return(dummyone.next);
}
/* letusMoveNode() function is a function which takes the node from the front of the
source, and move it to the front of the dest.
Before calling letusMoveNode():
source == {1, 2, 3}
dest == {1, 2, 3}
Affter calling letusMoveNode():
source == {3, 4}
dest == {1, 2, 3, 4} */
void letusMoveNode(struct node** destReference, struct node** sourceReference)
{
/*This is the front source node */
struct node* newNode = *sourceReference;
assert(newNode != NULL);
/* now we will advance the source pointer */
*sourceReference = newNode->next;
/*next we will link the old dest off the new node */
newNode->next = *destReference;
/* Fineally we will move dest to point to the new node */
*destReference = newNode;
}
/* This IS A function which is used to insert a node at the beginning of the linked list */
void insertpush(struct node** head_reference, int new_data)
{
/* This is used to allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* now we will put in the data */
new_node->data = new_data;
/* The next step is to link the old list off the new node */
new_node->next = (*head_reference);
/*Finally we will move the head to point to the new node */
(*head_reference) = new_node;
}
/* This is a function to print nodes in a given linked list */
void printList(struct node *node)
{
while (node!=NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
}
/*This is the driver program to test ab.
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
How to do insertion sort on a singly linked list with no header using C?
Solution
/* C program for insertion sort on a linked list */
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
// Function to insert a given node in a sorted linked list
void sortedInsert(struct node**, struct node*);
// function to sort a singly linked list using insertion sort
void insertionSort(struct node **head_ref)
{
// Initialize sorted linked list
struct node *sorted = NULL;
// Traverse the given linked list and insert every
// node to sorted
struct node *current = *head_ref;
while (current != NULL)
{
// Store next for next iteration
struct node *next = current->next;
// insert current in sorted linked list
sortedInsert(&sorted, current);
// Update current
current = next;
}
// Update head_ref to point to sorted linked list
*head_ref = sorted;
}
/* function to insert a new_node in a list. Note that this
function expects a pointer to head_ref as this can modify the
head of the input linked list (similar to push())*/
void sortedInsert(struct node** head_ref, struct node* new_node)
{
struct node* current;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->data >= new_node->data)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
/* Locate the node before the point of insertion */
current = *head_ref;
while (current->next!=NULL &&
current->next->data < new_node->data)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
/* BELOW FUNCTIONS ARE JUST UTILITY TO TEST sortedInsert */
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
/* A utility function to insert a node at the beginning of linked list */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node = new node;
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
// Driver program to test above functions
int main()
{
struct node *a = NULL;
push(&a, 5);
push(&a, 20);
push(&a, 4);
push(&a, 3);
push(&a, 30);
printf(\"Linked List before sorting \ \");
printList(a);
insertionSort(&a);
printf(\"\ Linked List after sorting \ \");
printList(a);
return 0;
}
/* C program for insertion sort on a linked list */
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
// Function to insert a given node in a sorted linked list
void sortedInsert(struct node**, struct node*);
// function to sort a singly linked list using insertion sort
void insertionSort(struct node **head_ref)
{
// Initialize sorted linked list
struct node *sorted = NULL;
// Traverse the given linked list and insert every
// node to sorted
struct node *current = *head_ref;
while (current != NULL)
{
// Store next for next iteration
struct.
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED
HELP FIXING THIS CODE?
THIS IS THE PROBLEM
Write a program that allows the user to enter two positive integers and outputs their sum. Sounds
simple? Here\'s the catch: The numbers may be any size! They may be way too large to store in a
single variable. You may not assume any particular maximum number of digits.
HERE IS THE CODE
#include
#include
struct node /* Linked list node*/
{
int data;
struct node* next;
};
struct node *newNode(int data) /* Function to create a new node with giving the data*/
{
struct node *new_node = (struct node *) malloc(sizeof(struct node));
new_node->data = data;
new_node->next = NULL;
return new_node;
}
void push(struct node** head_ref, int new_data) /* Function to insert a node at the beginning of
the Doubly Linked List*/
{
struct node* new_node = newNode(new_data); /*allocate a node*/
new_node->next = (*head_ref); /* link the old list off to the new node*/
(*head_ref) = new_node; /*move the head to point to the new node*/
}
/* Adding the contents of two linked lists and return the head node of resultant list*/
struct node* addTwoLists (struct node* first, struct node* second)
{
struct node* res = NULL; /* res is head node of the resultant list*/
struct node *temp, *prev = NULL;
int carry = 0, sum;
while (first != NULL || second != NULL) /*while both the lists exists*/
{
/* Calculate value of next digit in resultant list.
// The next digit is sum of following things
// (i) Carry
// (ii) Next digit of first list (if there is a next digit)
// (ii) Next digit of second list (if there is a next digit)*/
sum = carry + (first? first->data: 0) + (second? second->data: 0);
carry = (sum >= 10)? 1 : 0; /* update carry for next calulation*/
sum = sum % 10; /*update sum if it is greater than 10*/
temp = newNode(sum); /*Create a new node with sum as data*/
if(res == NULL) /*if this is the first node then set it as head of the resultant list*/
res = temp;
else /* If this is not the first node then connect it to the rest.*/
prev->next = temp;
prev = temp; /* Set prev for next insertion*/
if (first) first = first->next; /* Move first pointers to next node*/
if (second) second = second->next; /*Move second pointer to the next node*/
}
if (carry > 0)
temp->next = newNode(carry);
return res; /* return head of the resultant list*/
}
void printList(struct node *node) /* function to print a linked list*/
{
while(node != NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
printf(\"\ \");
}
int main(void) /* program to test above function*/
{
struct node* res = NULL;
struct node* first = NULL;
struct node* second = NULL;
printf(\"Enter first positive integer: \");
scanf(\"%d\",&first);
printList(first);
printf(\"Enter second positive integer: \");
scanf(\"%d\",&second);
printList(second);
/*Add the two lists and see result*/
res = addTwoLists(first, second);
printf(\"Sum is: %d\");
printList(res);
return 0;
}
Solution
#include
#include
typedef struct Node
{
int da.
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
C++
Write a method Node *Node::reverse() which reverses a list.
Solution
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Function to reverse the linked list */
static void reverse(struct node** head_ref)
{
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head_ref = prev;
}
/* Function to push a node */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
/* Driver program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
push(&head, 20);
push(&head, 4);
push(&head, 15);
push(&head, 85);
printf(\"Given linked list\ \");
printList(head);
reverse(&head);
printf(\"\ Reversed Linked list \ \");
printList(head);
getchar();
}.
1
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Takes head pointer of the linked list and index
as arguments and return data at index*/
int GetNth(struct node* head, int index)
{
struct node* current = head;
int count = 0; /* the index of the node we\'re currently
looking at */
while (current != NULL)
{
if (count == index)
return(current->data);
count++;
current = current->next;
}
/* if we get to this line, the caller was asking
for a non-existent element so we assert fail */
assert(0);
}
/* Drier program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
/* Use push() to construct below list
1->12->1->4->1 */
push(&head, 1);
push(&head, 4);
push(&head, 1);
push(&head, 12);
push(&head, 1);
/* Check the count function */
printf(\"Element at index 3 is %d\", GetNth(head, 3));
getchar();
}
2
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Takes head pointer of the linked list and index
as arguments and return data at index*/
int GetNth(struct node* head, int index)
{
struct node* current = head;
int count = 0; /* the index of the node we\'re currently
looking at */
while (current != NULL)
{
if (count == index)
return(current->data);
count++;
current = current->next;
}
/* if we get to this line, the caller was asking
for a non-existent element so we assert fail */
assert(0);
}
/* Drier program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
/* Use push() to construct below list
1->12->1->4->1 */
push(&head, 1);
push(&head, 4);
push(&head, 1);
push(&head, 12);
push(&head, 1);
/* Check the count function */
printf(\"Element at index 3 is %d\", GetNth(head, 3));
getchar();
}
Solution
1
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node*.
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
Use C++ Write a function to merge two doubly linked lists. The input.pdfshalins6
Use C++ Write a function to merge two doubly linked lists. The input lists have their elements in
sorted order, from lowest to highest. The output list should also be sorted from lowest to highest.
Your algorithm should run in linear time on the length of the output list. Provide an algorithm for
your function Implement and show some samples of your running function
Solution
/* This is a C++ program to merge two sorted linked lists and produce a list in a
Sorted order */
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* This function is used to pull off the front node of the source and put it in destnation */
void letusMoveNode(struct node** destRef, struct node** sourceRef);
/* This is a function used for performing merging of two linked lists.It takes two lists sorted in
increasing order, and splices
their nodes together to make one big sorted list which
is returned. */
struct node* letssortlists(struct node* a, struct node* b)
{
/* Let us first have dummyone first node to hang the result on */
struct node dummyone;
/*next the tail points to the last result node */
struct node* tail = &dummyone;
/* As a result, tail->next is the place to add new nodes
to the result. */
dummyone.next = NULL;
while (1)
{
if (a == NULL)
{
/*we will check that if either list runs out, use the
other list */
tail->next = b;
break;
}
else if (b == NULL)
{
tail->next = a;
break;
}
if (a->data <= b->data)
letusMoveNode(&(tail->next), &a);
else
letusMoveNode(&(tail->next), &b);
tail = tail->next;
}
return(dummyone.next);
}
/* letusMoveNode() function is a function which takes the node from the front of the
source, and move it to the front of the dest.
Before calling letusMoveNode():
source == {1, 2, 3}
dest == {1, 2, 3}
Affter calling letusMoveNode():
source == {3, 4}
dest == {1, 2, 3, 4} */
void letusMoveNode(struct node** destReference, struct node** sourceReference)
{
/*This is the front source node */
struct node* newNode = *sourceReference;
assert(newNode != NULL);
/* now we will advance the source pointer */
*sourceReference = newNode->next;
/*next we will link the old dest off the new node */
newNode->next = *destReference;
/* Fineally we will move dest to point to the new node */
*destReference = newNode;
}
/* This IS A function which is used to insert a node at the beginning of the linked list */
void insertpush(struct node** head_reference, int new_data)
{
/* This is used to allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* now we will put in the data */
new_node->data = new_data;
/* The next step is to link the old list off the new node */
new_node->next = (*head_reference);
/*Finally we will move the head to point to the new node */
(*head_reference) = new_node;
}
/* This is a function to print nodes in a given linked list */
void printList(struct node *node)
{
while (node!=NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
}
/*This is the driver program to test ab.
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
How to do insertion sort on a singly linked list with no header using C?
Solution
/* C program for insertion sort on a linked list */
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
// Function to insert a given node in a sorted linked list
void sortedInsert(struct node**, struct node*);
// function to sort a singly linked list using insertion sort
void insertionSort(struct node **head_ref)
{
// Initialize sorted linked list
struct node *sorted = NULL;
// Traverse the given linked list and insert every
// node to sorted
struct node *current = *head_ref;
while (current != NULL)
{
// Store next for next iteration
struct node *next = current->next;
// insert current in sorted linked list
sortedInsert(&sorted, current);
// Update current
current = next;
}
// Update head_ref to point to sorted linked list
*head_ref = sorted;
}
/* function to insert a new_node in a list. Note that this
function expects a pointer to head_ref as this can modify the
head of the input linked list (similar to push())*/
void sortedInsert(struct node** head_ref, struct node* new_node)
{
struct node* current;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->data >= new_node->data)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
/* Locate the node before the point of insertion */
current = *head_ref;
while (current->next!=NULL &&
current->next->data < new_node->data)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
/* BELOW FUNCTIONS ARE JUST UTILITY TO TEST sortedInsert */
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
/* A utility function to insert a node at the beginning of linked list */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node = new node;
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
// Driver program to test above functions
int main()
{
struct node *a = NULL;
push(&a, 5);
push(&a, 20);
push(&a, 4);
push(&a, 3);
push(&a, 30);
printf(\"Linked List before sorting \ \");
printList(a);
insertionSort(&a);
printf(\"\ Linked List after sorting \ \");
printList(a);
return 0;
}
/* C program for insertion sort on a linked list */
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
// Function to insert a given node in a sorted linked list
void sortedInsert(struct node**, struct node*);
// function to sort a singly linked list using insertion sort
void insertionSort(struct node **head_ref)
{
// Initialize sorted linked list
struct node *sorted = NULL;
// Traverse the given linked list and insert every
// node to sorted
struct node *current = *head_ref;
while (current != NULL)
{
// Store next for next iteration
struct.
Program to insert in a sorted list #includestdio.h#include.pdfsudhirchourasia86
* Program to insert in a sorted list */
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function to insert a new_node in a list. Note that this
function expects a pointer to head_ref as this can modify the
head of the input linked list (similar to push())*/
void sortedInsert(struct node** head_ref, struct node* new_node)
{
struct node* current;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->data >= new_node->data)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
/* Locate the node before the point of insertion */
current = *head_ref;
while (current->next!=NULL &&
current->next->data < new_node->data)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
/* BELOW FUNCTIONS ARE JUST UTILITY TO TEST sortedInsert */
/* A utility function to create a new node */
struct node *newNode(int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
new_node->next = NULL;
return new_node;
}
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
/* Drier program to test count function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
struct node *new_node = newNode(5);
sortedInsert(&head, new_node);
new_node = newNode(10);
sortedInsert(&head, new_node);
new_node = newNode(7);
sortedInsert(&head, new_node);
new_node = newNode(3);
sortedInsert(&head, new_node);
new_node = newNode(1);
sortedInsert(&head, new_node);
new_node = newNode(9);
sortedInsert(&head, new_node);
printf(\"\ Created Linked List\ \");
printList(head);
return 0;
}
public class Listnode {
//*** fields ***
private Object data;
private Listnode next;
//*** methods ***
// 2 constructors
public Listnode(Object d) {
this(d, null);
}
public Listnode(Object d, Listnode n) {
data = d;
next = n;
}
// access to fields
public Object getData() {
return data;
}
public Listnode getNext() {
return next;
}
// modify fields
public void setData(Object ob) {
data = ob;
}
public void setNext(Listnode n) {
next = n;
}
}
Thsi below program print out all the varibles in SLL
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Takes head pointer of the linked list and index
as arguments and return data at index*/
int GetNth(struct node* head, int index)
{
struct node* current = head;
int .
Below is a depiction of a doubly-linked list implementation of the bag.docxgilliandunce53776
Below is a depiction of a doubly-linked list implementation of the bag ADT with two sentinels -one at the head and one at the tail. Strict DLink { TYPE value; strict DLink * next; struct DLink * prev;}; strict linked List { int size; struct DLink *frontSentinel; struct DLink *backSentinel;}; Write a function that at first reverses the list and then prints the values of the links in the list from front to back. Don\'t redirect to any other function. You must use assertions if necessary.
Solution
/* Program to reverse a doubly linked list */
#include <stdio.h>
#include <stdlib.h>
/* a node of the doubly linked list */
struct node
{
int data;
struct node *n;
struct node *pr;
};
/* Function to reverse a Doubly Linked List */
void reverse(struct node **head_r)
{
struct node *t = NULL;
struct node *cur = *head_r;
/* swap next and prev for all nodes of
doubly linked list */
while (cur != NULL)
{
t = cur->pr;
cur->pr = cur->n;
cur->n = t;
cur = cur->pr;
}
/* Before changing head, check for the cases like empty
list and list with only one node */
if(t != NULL )
*head_r = t->pr;
}
/* UTILITY FUNCTIONS */
/* Function to insert a node at the beginging of the Doubly Linked List */
void push(struct node** head_r, int new_data)
{
/* allocate node */
struct node* n_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
n_node->data = n_data;
/* since we are adding at the begining,
prev is always NULL */
n_node->pr = NULL;
/* link the old list off the new node */
n_node->n = (*head_r);
/* change prev of head node to new node */
if((*head_r) != NULL)
(*head_r)->pr = n_node ;
/* move the head to point to the new node */
(*head_r) = n_node;
}
/* Function to print nodes in a given doubly linked list
This function is same as printList() of singly linked lsit */
void printList(struct node *node)
{
while(node!=NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
}
/* Drier program to test above functions*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
/* Let us create a sorted linked list to test the functions
Created linked list will be 10->8->4->2 */
push(&head, 2);
push(&head, 4);
push(&head, 8);
push(&head, 10);
printf(\"\ Original Linked list \");
printList(head);
/* Reverse doubly linked list */
reverse(&head);
printf(\"\ Reversed Linked list \");
printList(head);
getchar();
}
.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
C++: Doubly-Linked Lists
The goal of the exercise is to implement a class List of doubly- linked lists.
My goal is to implement the class in a file doubly-linked.cpp.
The class List implements lists using the following structures for list ele- ments:
struct Node { int val ;
Node next;
Node prev; };
Each Node contains a value (an integer) and two pointers: one meant to point to the next element
of the list and one meant to point to the previous element in the list. The class provides the
following methods that you need to implement:
• A constructor and a destructor, with no arguments;
• void insert(int n): insert an integer at the end of the list;
• void reverse(): reverse the list;
• void print(): print the list to cout in the same format as the input (i.e. integers separated by
spaces);
doubly-linked.h
#ifndef __dll__
#define __dll__
#include
using namespace std;
// Basic structure to store elements of a list
struct Node {
int val; // contains the value
Node * next; // pointer to the next element in the list
Node * prev; // pointer to the previous element in the list
};
// Class List
class List {
public:
List(void); // Constructor
~List(void); // Destructor
void insert(int n); // This should insert n in the list
void reverse(void); // This should reverse the list
void print(void); // This shoiuld print the list
private:
Node * first; // Pointer to the first (if any) element in the list
};
#endif
main.cpp
#include
#include \"doubly-linked.h\"
using namespace std;
int main(void){
List l;
int n;
while(cin >> n){
l.insert(n);
}
// Print list as read from cin
l.print();
// Reverse the list and print it
l.reverse();
l.print();
// Reverse again and print it
l.reverse();
l.print();
return 0;
}
Solution
#include
using namespace std;
/* Linked list structure */
struct list {
struct list *prev;
int data;
struct list *next;
} *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class linkedlist {
public:
/* Function for create/insert node at the beginning of Linked list */
void insrt_frnt() {
list *addBeg = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addBeg->data;
if(first == NULL) {
addBeg->prev = NULL;
addBeg->next = NULL;
first = addBeg;
last = addBeg;
cout << \"Linked list Created!\" << endl;
}
else {
addBeg->prev = NULL;
first->prev = addBeg;
addBeg->next = first;
first = addBeg;
cout << \"Data Inserted at the beginning of the Linked list!\" << endl;
}
}
/* Function for create/insert node at the end of Linked list */
void insrt_end() {
list *addEnd = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addEnd->data;
if(first == NULL) {
addEnd->prev = NULL;
addEnd->next = NULL;
first = addEnd;
last = addEnd;
cout << \"Linked list Created!\" << endl;
}
else {
addEnd->next = NULL;
last->next = addEnd;
addEnd->prev = last;
last = addEnd;
cout << \"Data Inserted at the end of the Linked list!\" << endl;
}
}
/* Function for Display Linked list */
void display() {
node = first;
cout << \"List of data in L.
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
Brianca plans to save $5,000, $1,000, and $42,000 a year over the next three years, respectively. How much would you need to deposit in one lump sum today to have the same amount as Brianca three years from now if you both earn 10.9 percent, compounded annually? $36,115 $35,192 $43,282 $41,635 $35,372
.
A)B) C++ program to create a Complete Binary tree from its Lin.pdfanton291
A)
B)
// C++ program to create a Complete Binary tree from its Linked List
// Representation
#include
#include
#include
using namespace std;
// Linked list node
struct ListNode
{
int data;
ListNode* next;
};
// Binary tree node structure
struct BinaryTreeNode
{
int data;
BinaryTreeNode *left, *right;
};
// Function to insert a node at the beginning of the Linked List
void push(struct ListNode** head_ref, int new_data)
{
// allocate node and assign data
struct ListNode* new_node = new ListNode;
new_node->data = new_data;
// link the old list off the new node
new_node->next = (*head_ref);
// move the head to point to the new node
(*head_ref) = new_node;
}
// method to create a new binary tree node from the given data
BinaryTreeNode* newBinaryTreeNode(int data)
{
BinaryTreeNode *temp = new BinaryTreeNode;
temp->data = data;
temp->left = temp->right = NULL;
return temp;
}
// converts a given linked list representing a complete binary tree into the
// linked representation of binary tree.
void convertList2Binary(ListNode *head, BinaryTreeNode* &root)
{
// queue to store the parent nodes
queue q;
// Base Case
if (head == NULL)
{
root = NULL; // Note that root is passed by reference
return;
}
// 1.) The first node is always the root node, and add it to the queue
root = newBinaryTreeNode(head->data);
q.push(root);
// advance the pointer to the next node
head = head->next;
// until the end of linked list is reached, do the following steps
while (head)
{
// 2.a) take the parent node from the q and remove it from q
BinaryTreeNode* parent = q.front();
q.pop();
// 2.c) take next two nodes from the linked list. We will add
// them as children of the current parent node in step 2.b. Push them
// into the queue so that they will be parents to the future nodes
BinaryTreeNode *leftChild = NULL, *rightChild = NULL;
leftChild = newBinaryTreeNode(head->data);
q.push(leftChild);
head = head->next;
if (head)
{
rightChild = newBinaryTreeNode(head->data);
q.push(rightChild);
head = head->next;
}
// 2.b) assign the left and right children of parent
parent->left = leftChild;
parent->right = rightChild;
}
}
// Utility function to traverse the binary tree after conversion
void inorderTraversal(BinaryTreeNode* root)
{
if (root)
{
inorderTraversal( root->left );
cout << root->data << \" \";
inorderTraversal( root->right );
}
}
// Driver program to test above functions
int main()
{
// create a linked list shown in above diagram
struct ListNode* head = NULL;
push(&head, 36); /* Last node of Linked List */
push(&head, 30);
push(&head, 25);
push(&head, 15);
push(&head, 12);
push(&head, 10); /* First node of Linked List */
BinaryTreeNode *root;
convertList2Binary(head, root);
cout << \"Inorder Traversal of the constructed Binary Tree is: \ \";
inorderTraversal(root);
return 0;
}
c)
#include
#include
using namespace std;
template
class bintree
{
bintree *left;
T data;
bintree *right;
public :
bintree()
{
left=right=NULL;
}
void create();
void preorder();
void inorder();
void pos.
In the class we extensively discussed a node class called IntNode in.pdfarjunstores123
In the class we extensively discussed a node class called IntNode in which each linked list node
contains an integer and each node is linked forward to the next element in the list. Implement a
node class called DoublyIntNode in which each node contains an integer number and each node
is linked not only forward to the next element in the list but also backward to the previous
element in the list. Your implementation of DoublyIntNode should adapt and implement all the
methods of IntNode including the following methods:
Constructor for DoublyIntNode
addNodeAfter, removeNodeAfter
getData, setData
getForeLink, setForeLink
getBackLink, setBackLink
listCopy
listCopyWithTail
listLength
listPart
listPosition
listSearch
IntNode and Node classes:
public class IntNode{
private int data;
private IntNode link;
// methods here
}
public class Node {
private E data;
private Node link;
// methods here
}
Solution
program
#include
using namespace std;
struct list
{
struct list *prev;
int data;
struct list *next;
}
*node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class Dlist
{
public:
void insert_beg() {
list *addBeg = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addBeg->data;
if(first == NULL) {
addBeg->prev = NULL;
addBeg->next = NULL;
first = addBeg;
last = addBeg;
cout << \"Linked list Created!\" << endl;
}
else {
addBeg->prev = NULL;
first->prev = addBeg;
addBeg->next = first;
first = addBeg;
cout << \"Data Inserted at the beginning of the Linked list!\" << endl;
}
}
void insert_end() {
list *addEnd = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addEnd->data;
if(first == NULL) {
addEnd->prev = NULL;
addEnd->next = NULL;
first = addEnd;
last = addEnd;
cout << \"Linked list Created!\" << endl;
}
else {
addEnd->next = NULL;
last->next = addEnd;
addEnd->prev = last;
last = addEnd;
cout << \"Data Inserted at the end of the Linked list!\" << endl;
}
}
void display() {
node = first;
cout << \"List of data in Linked list in Ascending order!\" << endl;
while(node != NULL) {
cout << node->data << endl;
node = node->next;
}
node = last;
cout << \"List of data in Linked list in Descending order!\" << endl;
while(node != NULL) {
cout << node->data << endl;
node = node->prev;
}
}
void del()
{
int count = 0, number, i;
node = node1 = node2 = first;
for(node = first; node != NULL; node = node->next)
cout << \"Enter value for the node:\" << endl;
count++;
display();
cout << count << \" nodes available here!\" << endl;
cout << \"Enter the node number which you want to delete:\" << endl;
cin >> number;
if(number != 1)
{
if(number < count && number > 0)
{
for(i = 2; i <= number; i++)
node = node->next;
for(i = 2; i <= number-1; i++)
node1 = node1->next;
for(i = 2; i <= number+1; i++)
node2 = node2->next;
node2->prev = node1;
node1->next = node2;
node->prev = NULL;
node->next = NULL;
node = NULL;
}
else if(number == count)
{
node = last;
last = node->prev;
last->next = NULL;
node = NULL;
}
else
cout << \"Invalid node.
Write a program in C that does the followinga) Builds a simple li.pdfkavithaarp
Write a program in C that does the following:
a) Builds a simple linked list consisting of 10 nodes each of which contains a random integer
between 50 and 100 inclusive. The list is to be built in main() and must be a local variable in
main().
b) Includes a user-defined function named printout(arg) that takes in the head pointer of the
already-built linked list as an argument and prints out the contents of the linked list to the screen,
starting from the head of the list to the tail. See the output below.
Node #0 contains 53
Node #1 contains 78
Node #2 contains 95
. . .
Node #20 contains 100
c) Includes a user-defined function called sum() that adds up the contents of the data members of
each node in the list, and prints out the total as follows:
The sum total of all nodes in this list is
d) Includes a user-defined function called reverse() that takes in the head pointer of the already-
built linked list as an argument and will physically reverse the order of the nodes in the list (i.e.,
the new head will be the old tail and the new tail will be the old head of the list). Use the
function printout() to output its contents now in reverse order. This does NOT mean that it will
be read backwards, but rather, the reversed list will be read from head to tail!
** PLEASE MAKE SURE THIS PROGRAM WORKS IN C LANGUAGE !!
Solution
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Function to reverse the linked list */
static void reverse(struct node** head_ref)
{
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head_ref = prev;
}
/* Function to push a node */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
int i=0;
while(temp != NULL)
{
printf(\"Node #%d contains %d\ \",i, temp->data);
temp = temp->next;
i++;
}
}
void sum(struct node *head)
{
int sum=0;
struct node *temp = head;
while(temp != NULL)
{
//printf(\"%d \", temp->data);
sum+=temp->data;
temp = temp->next;
}
printf(\"\ The sum total of all nodes in this list is %d\ \",sum);
}
/* Driver program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
int i,t;
for(i=0;i<10;i++)
{
// (rand() % 51) generates random number between 0 and 50 adding 50 generates random
number beween 50 and 100 both inclusive
t=(rand() % 51)+50;
push(&head, t);
}
printf(\"Given linked list\ \");
printList(head);
sum(head);
reverse(&head);
printf(\"\ Reversed Linked list \ \");
printList(head);
return 0;
}.
Consider a double-linked linked list implementation with the followin.pdfsales98
Consider a double-linked linked list implementation with the following node: struct Node {int
data; Node *prev; Node *next;} Write a copyList method that is not a member of any class.
The method should take a head pointer and return another pointer. Do not modify the input.
Solution
struct Node {
Node *prev; // previous node
Node *next; // next node
int data; // stored value
};
#include
#include \"List.h\" // std: #include
using namespace std;
typedef DataList ; // std: typedef list Data;
int main() {
Data k;
// back stuff
k.push_back(5);
k.push_back(6);
cout << k.back() << endl;
k.pop_back();
// front stuff
k.push_front(4);
k.push_front(3);
cout << k.front() << endl;
k.pop_front();
// forward iterator
Data::iterator pos;
for (pos = k.begin(); pos != k.end(); ++pos)
cout << *pos << endl;
// output and delete list
while (!k.empty()) {
cout << k.front() << endl;
k.pop_front();
}
k.push_front(5);
k.push_front(6);
// remove and erase
k.remove(5);
pos = k.begin();
k.erase(pos);
k.push_front(5);
k.push_front(6);
// copy constructor
Data l = k;
// assignment operator
Data m;
m = k;
return 0;
}
// List.h
struct Node;
classIterator List;
class List {
public:
typedef ListIterator iterator;
// constructor
List();
// destructor
virtual ~List();
// copy constructor
List(const List& k);
// assignment operator
List& operator=(const List& k);
// insert value in front of list
void push_front(double data);
// insert value in back of list
void push_back(double data);
// delete value from front of list
void pop_front();
// delete value from back of list
void pop_back();
// return value on front of list
double front() const;
// return value on back of list
double back() const;
// delete value specified by iterator
void erase(const iterator& i);
// delete all nodes with specified value
void remove(double data);
// return true if list is empty
bool empty() const;
// return reference to first element in list
iterator begin() const;
// return reference to one past last element in list
iterator end() const;
private:
Node *head; // head of list
};
class ListIterator {
public:
// default constructor
ListIterator() {
i = 0;
}
// construct iterator for given pointer (used for begin/end)
ListIterator(Node *p) {
i = p;
}
// convert iterator to Node*
operator Node*() const {
return i;
}
// test two iterators for not equal
bool operator!=(const ListIterator& k) const {
return i != k.i;
}
// preincrement operator
ListIterator& operator++() {
i = i->next;
return *this;
}
// return value associated with iterator
double& operator*() const {
return i->data;
}
private:
Node *i; // current value of iterator
};
list.cpp
// delete list
static void deleteList(Node *head) {
Node *p = head->next;
while (p != head) {
Node *next = p->next;
delete p;
p = next;
}
delete head;
}
// copy list
static void copyList(const Node *from, Node *&to) {
// create dummy header
to = new Node;
to->next = to->prev = to;
// copy nodes
for (Node *p = from->next; p != from; p = p->next) {
Node *t = new Node;
t.
Please correct my errors upvote Clears our entire .pdfkitty811
Please correct my errors. upvote
/**
* Clears our entire list, making it empty
* Remember: All removal operations should be memory-leak free.
*/
void clear()
{
// Set a pointer to the head of the list
Node<T> *current = head_;
// Loop through each node in the list
while (current != nullptr)
{
Node<T> *next = current->getNext();
delete current;
current = next;
}
// Set head and tail pointers to null and reset the size of the list
head_ = nullptr;
tail_ = nullptr;
size_ = 0;
}
/**
* Insert an element after the node pointed to by the pos Iterator
*
* If the list is currently empty,
* ignore the iterator and just make the new node at the head/tail (list of length 1).
*
* If the incoming iterator is this->end(), insert the element at the tail
*
* Should return an iterator that points to the newly added node
*
* To avoid repeated code, it might be a good idea to have other methods
* rely on this one.
*/
Iterator insert_after(Iterator pos, const T& value) {
}
/**
* Insert a new element after the index pos.
* Should work with an empty list.
*
* Should return an iterator pointing to the newly created node
*
* To reduce repeated code, you may want to simply find
* an iterator to the node at the pos index, then
* send it to the other overload of this method.
*/
Iterator insert_after(size_t pos, const T &value)
{
Iterator it = begin();
for (size_t i = 0; i < pos && it != end(); i++)
{
++it;
}
return insert_after(it, value);
}
/**
* Erase the node pointed to by the Iterators cursor.
*
* If the 'pos' iterator does not point to a valid node,
* throw an std::range_error
*
* Return an iterator to the node AFTER the one we erased,
* or this->end() if we just erased the tail
*/
Iterator erase(Iterator pos)
{
Node<T> *node = pos.node_;
if (node == nullptr || node == head_ || node == tail_)
{
throw std::range_error("Invalid iterator");
}
Node<T> *prevNode = node->prev_;
Node<T> *nextNode = node->next_;
// Updates the next_ pointer of the previous node to point to the next node or updates the head_
pointer
if (prevNode != nullptr)
{
prevNode->next_ = nextNode;
}
else
{
head_ = nextNode;
}
if (nextNode != nullptr)
{
nextNode->prev_ = prevNode;
}
else
{
tail_ = prevNode;
}
Iterator nextIt(nextNode, head_, tail_);
delete node;
return nextIt;
}
/**
* Add an element just after the one pointed to by the 'pos' iterator
*
* Should return an iterator pointing to the newly created node
*/
Iterator push_after(Iterator pos, const T &value)
{
Node<T> *node = pos.node_;
if (node == nullptr)
{
throw std::range_error("Invalid iterator");
}
Node<T> *nextNode = node->next_;
Node<T> *newNode = new Node(value, node, nextNode);
node->next_ = newNode;
if (nextNode != nullptr)
{
nextNode->prev_ = newNode;
}
else
{
tail_ = newNode;
}
return Iterator(newNode, head_, tail_);
}
/**
* Add a new element to the front of our list.
*/
void push_front(const T &value)
{
Node<T> *new_node = new Node<T>(value, nullptr, head_);
if (head_ == nullptr)
{
tail_ = new_node;
}
else
{
head_->setPrevious(new.
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
Using the provided table interface table.h and the sample linked list code linkedList.c, complete
an implementation of the Table ADT. Make sure that you apply the concepts of design by
contract (DbC) to your implementation.
Once you have fully implemented the table, create a main.c file that implements a testing
framework for your table.
Your table implementation must ensure that values inserted are unique, and internally sorted
within a linked list.
table.h
linkedList.c
Solution
khsdg
#include
#include
typedef enum BOOL { false, true } bool;
// Linked list node definition
typedef struct Node node;
struct Node
{
int number;
node *next;
};
static node *top = NULL;
// used to track where we are for the list traversal methods
static node *traverseNode = NULL;
// \"destroy\" will deallocate all nodes in a linked list object
// and will set \"top\" to NULL.
void destroy()
{
node *curr = top;
node *temp = NULL;
while ( curr != NULL )
{
// flip order to see it blow up...
temp = curr;
curr = curr->next;
free( temp );
}
top = NULL;
}
// \"build\" will create an ordered linked list consisting
// of the first \"size\" even integers.
void build( int size )
{
node *newNode = NULL;
int i = 0;
// make sure we don\'t have a list yet
destroy();
for ( i=size ; i>0 ; i-- )
{
newNode = malloc( sizeof( node ) );
newNode->number = i*2;
newNode->next = top;
top = newNode;
}
}
// starts a list traversal by getting the data at top.
// returns false if top == NULL.
bool firstNode( int *item )
{
bool result = false;
if ( top )
{
*item = top->number;
traverseNode = top->next;
result = true;
}
return result;
}
// gets the data at the current traversal node and increments the traversal.
// returns false if we\'re at the end of the list.
bool nextNode( int *item )
{
bool result = false;
if ( traverseNode )
{
*item = traverseNode->number;
traverseNode = traverseNode->next;
result = true;
}
return result;
}
// \"print\" will output an object\'s entire linked list
// to the standard output device -- one \"number\" per line.
void print()
{
int value;
if ( firstNode( &value ) )
{
do
{
printf( \"%d\ \", value );
} while ( nextNode( &value ) );
}
}
int main( int argc, char *argv[] )
{
build( 10 );
print();
destroy();
build( 5 );
build( 20 );
print();
destroy();
return 0;
}.
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
C++ problem
Part 1: Recursive Print (40 pts)
Please write the recursive List reverse print function, whose iterative version we wrote in class.
Below are the function signatures for the functions you are going to need:
public:
/**Additional Operations*/
void print_reverse();
//Wrapper function that calls the reverse helper function to print a list in reverse
//prints nothing if the List is empty
private:
void reverse(Nodeptr node);
//Helper function for the public printReverse() function.
//Recursively prints the data in a List in reverse.
Why do we need the private helper function here?
Since we are going to be reversing our list node by node, in a recursive fashion, we want to pass
a one node at a time to our reverse function.
However, since our nodes are private, we cannot access them if we call the function inside of
main.
Add these function signatures to your List.h file along with your other function prototypes inside
the class definition.
Make sure that you place the reverse function inside the private portion of your List class
definition and the print_reverse function prototype to the public portion of your List class
definition.
Now, implement these two functions inside of List.h, under your section for additional
operations.
Important: Test each function carefully inside of your ListTest.cpp to make sure that it is
working properly.
Part 2: Adding an Index to Your List Nodes (20 pts)
Next, you will add the following functions to your List.h
/**Accessor Functions*/
int get_index();
//Indicates the index of the Node where the iterator is currently pointing
//Nodes are numbered from 1 to length of the list
//Pre: length != 0
//Pre: !off_end()
...
int List::get_index()
{
//Implement the function here
}
/**Manipulation Procedures*/
void scroll_to_index(int index);
//Moves the iterator to the node whose index is specified by the user
//Pre: length != 0
...
void scroll_to_index(int index)
{
//Implement function here
}
Part 3: Implementing Search as Part of Your List (40 pts)
Now, we are going to add two search functions to our List so that we can search for elements in
our List.
The first of these functions is going to be a simple linear search function.
You will need to add the following function prototype and function definition to your List.h:
/**Additional Operations*/
int linear_search(listitem item);
//Searchs the list, element by element, from the start of the List to the end of the List
//Returns the index of the element, if it is found in the List
//Returns -1 if the element is not in the List
//Pre: length != 0
...
int List::linear_search(listitem item)
{
//Implement the function here
}
You are also going to add a function to perform recursive binary search on your List.
You will need to add the following function prototype and function definition to your List.h:
int binary_search(int low, int high, listitem item);
//Recursively searchs the list by dividing the search space in half
//Returns the index of the element, if it is fo.
Write an algorithm that reads a list of integers from the keyboard, .pdfArrowdeepak
Write an algorithm that reads a list of integers from the keyboard, creates
a list of them using linked list implementation, and prints the result
Solution
/*
Algorithm:
Implementation of linked list.
Create a node type class which will hold an integer and next pointer to point to another node.
Create a constructor which will construct an object of type node with the integer type data as the
only parameter
and initializing next pointer to NULL.
Create LinkedList class which will only have head pointer.
Create a constructor which will initialize this head pointer to NULL.
Create a append method which will recieve an input of type integer from the user and append it
to LinkedList
using below steps:
1.Create a Node type object.
1.IF head is NULL assign a Node type object created in 1st step.
2.IF head is not NULL then traverse to the end of the linked list till you found a Node which has
next pointer
set to NULL.
3.Add Node type object created in first step to the next pointer of last node.
Create a print method which will traverse the list from the head of the linked list to the last
node(Node
with next pointer NULL) and while traversing it will keep printing the node data.
Get the userinput:
Ask user for integer continously till user input -1 and append all the integers to the linked list.
*/
PROGRAM:
#include
using namespace std;
class Node
{
public:
int data;
Node *next;
Node(int data)
{
this->data = data;
this->next = NULL;
}
};
class LinkedList
{
private:
Node *head;
public:
LinkedList()
{
head = NULL;
}
void addToFront(int data)
{
Node *temp = new Node(data);
if(head == NULL)
head = temp;
else
{
temp->next = head;
head = temp;
}
}
void append(int data)
{
Node *temp = new Node(data);
Node *current = head;
if(current == NULL)
{
head = temp;
return;
}
while(current->next != NULL)
{
current = current->next;
}
current->next = temp;
}
void print()
{
Node *current = head;
if(current == NULL)
cout << \"No element in list. \ \";
while(current != NULL)
{
cout << current->data << \" \";
current = current->next;
}
cout << endl;
}
void deleteLinkedList()
{
Node *prev;
Node *current = head;
while(current!=NULL)
{
prev = current;
current = current->next;
delete prev;
}
}
void deleteLastNode()
{
Node *current = head;
Node *prev = NULL;
if(current == NULL)
return;
while(current->next != NULL)
{
prev = current;
current = current->next;
}
if(prev == NULL)
{
delete current;
head = NULL;
}
else
{
prev->next = NULL;
delete current;
}
}
~LinkedList()
{
deleteLinkedList();
}
};
int main()
{
LinkedList list;
int data;
while(1)
{
cout << \"Enter the integer(-1 to Quit) : \";
cin >> data;
if(data==-1)
break;
list.append(data);
}
cout << \"Content of LinkedList is : \";
list.print();
return 0;
}
OUTPUT:
Enter the integer(-1 to Quit) : 1
Enter the integer(-1 to Quit) : 2
Enter the integer(-1 to Quit) : 3
Enter the integer(-1 to Quit) : 4
Enter the integer(-1 to Quit) : -1
Content of LinkedList is : 1 2 3 4.
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
Data Structures in C++
I am really new to C++, so links are really hard topic for me. It would be nice if you can provide
explanations of what doubly linked lists are and of some of you steps... Thank you
In this assignment, you will implement a doubly-linked list class, together with some list
operations. To make things easier, you’ll implement a list of int, rather than a template class.
Solution
A variable helps us to identify the data. For ex: int a = 5; Here 5 is identified through variable a.
Now, if we have collection of integers, we need some representation to identify them. We call it
array. For ex: int arr[5]
This array is nothing but a Data Structure.
So, a Data Structure is a way to group the data.
There are many Data Structures available like Arrays, Linked List, Doubly-Linked list, Stack,
Queue, etc.
Doubly-Linked list are the ones where you can traverse from the current node both in left and
right directions.
Why so many different types of Data Structures are required ?
Answer is very simple, grouping of data, storage of data and accessing the data is different.
For example, in case of Arrays we store all the data in contiguous locations.
What if we are not able to store the data in contiguous locations because we have huge data.
Answer is go for Linked List/Doubly-Linked list.
Here we can store the data anywhere and link the data through pointers.
I will try to provide comments for the code you have given. May be this can help you.
#pragma once
/*
dlist.h
Doubly-linked lists of ints
*/
#include
class dlist {
public:
dlist() { }
// Here we are creating a NODE, it has a integer value and two pointers.
// One pointer is to move to next node and other to go back to previous node.
struct node {
int value;
node* next;
node* prev;
};
// To return head pointer, i.e. start of the Doubly-Linked list.
node* head() const { return _head; }
// To return Tail pointer, i.e. end of the Doubly-Linked list.
node* tail() const { return _tail; }
// **** Implement ALL the following methods ****
// Returns the node at a particular index (0 is the head).
node* at(int index){
int cnt = 0;
struct node* tmp = head();
while(tmp!=NULL)
{
if (cnt+1 == index)
return tmp;
tmp = tmp->next;
}
}
// Insert a new value, after an existing one
void insert(node *previous, int value){
// check if the given previous is NULL
if (previous == NULL)
{
printf(\"the given previous node cannot be NULL\");
return;
}
// allocate new node
struct node* new_node =(struct node*) malloc(sizeof(struct node));
// put in the data
new_node->data = new_data;
// Make next of new node as next of previous
new_node->next = previous->next;
// Make the next of previous as new_node
previous->next = new_node;
// Make previous as previous of new_node
new_node->prev = previous;
// Change previous of new_node\'s next node
if (new_node->next != NULL)
new_node->next->prev = new_node;
}
// Delete the given node
void del(node* which){
struct node* head_ref = head();
/* base case */
if(*head_ref == NUL.
Program In C You are required to write an interactive C program that.pdfamitbagga0808
Program In C You are required to write an interactive C program that prompts the user for
commands, accepts commands from the keyboard (stdin) and executes those commands. When a
command requires output, it must be written to stdout. The program must continue to accept and
process commands until the user types the end command ourput, it must be writen to stdout. The
program must continue to accept and proces.commands The program deals with linked lists.
Each node of such a list contains a string of length at most 10, a positive integer (i.e., an integer
value 2 1) and a pointer to the next node of the list. For any node, the string and the integer
stored in that node will be referred to as the symbol and count for that node respectively. At all
times, the list must satisfy the following two important properties. 1. The symbols appearing in
the list are all distinct; that is, no two nodes have the same symbol. 2. When the list is scanned
from left to right, the counts must be in non-increasing order. An example of such a linked list is
shown below. Search 4 Maxval4 begin/ Loop head
Solution
/**********************************************/
/****** NAMES ******************** COMMANDS ***/
/* Insert Command : ins str */
/* Delete Command : del str */
/* Forced Delete Command : fde val */
/* Print Statistics Command : pst */
/* Print List Command : prl */
/* Print using Count Range Command: pcr v1 v2 */
/* Print Prefix Command : ppr str */
/* Print Suffix Command : psu str */
/* End Command : end */
/***********************************************/
#include
#include
#include
#define CSIZE 4
#define SSIZE 11
/* Struct for each node in the linked list */
struct node
{
int count;
char symbol[SSIZE];
struct node *next;
};
struct node *head;
/* Prototypes for the functions */
void insert(char *);
void delete(char *);
void forced_delete(int value);
void print_stats();
void print_list();
void print_count(int, int);
void print_prefix(char pre[]);
void print_suffix(char suf[]);
void sort_list();
/****************
** Main Method **
****************/
int main(void)
{
int count;
char symbol[SSIZE];
char cmd[CSIZE];
int v1;
int v2;
/* Enter commands */
printf(\"Command? \"); fflush(stdout);
scanf(\"%s\", cmd);
/* Check for command*/
while(strcmp(cmd,\"end\") != 0)
{
/* check which function to use */
if(strcmp(cmd,\"ins\") == 0) { scanf(\"%s\", symbol); insert(symbol); }
if(strcmp(cmd,\"del\") == 0) { scanf(\"%s\", symbol); delete(symbol); }
else if(strcmp(cmd,\"fde\")==0){scanf(\"%d\",&count); forced_delete(count); }
if(strcmp(cmd,\"pst\") == 0) { print_stats();}
if(strcmp(cmd,\"prl\") == 0) { print_list(); }
if(strcmp(cmd,\"pcr\") == 0) { scanf(\"%d %d\",&v1,&v2); print_count(v1,v2); }
if(strcmp(cmd,\"ppr\") == 0) { scanf(\"%s\", symbol); print_prefix(symbol);}
if(strcmp(cmd,\"psu\") == 0) { scanf(\"%s\", symbol); print_suffix(symbol);}
printf(\"Command? \"); fflush(stdout);
scanf(\"%s\", cmd);
}// End of While Loop
return 0;
}// End of main method
/*********.
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(" ".
Please complete the assignment listed below.Define and explain, us.docxajoy21
Please complete the assignment listed below.
Define and explain, using at least five sentence or on-task bullet notes for each. Each answer earns up to five points. For each answer, please make five different substantive points, earning one point each.
Transnational corporation
Gentrification
Renewable resources
Desertification
Photochemical smog
Biodiversity
Barriers to migration
Hierarchical diffusion
Militant fundamentalism
Urbanization
Eastern European cities
Hazardous waste
The Endangered Species Act
Subsidence
Water Quality
Deforestation
Wetlands
Central place theory
Soil degradation
Hydraulic fracturing (fracking)
Wind power
Oil sands
Models of urban form
Hinterland
Agglomeration economies
.
Please cite sources for each question. Do not use the same sources f.docxajoy21
Please cite sources for each question. Do not use the same sources for each question. Minimum of 2 resources and 300 words.
Briefly contrast the views of Locke and Rousseau on how children develop.
a) What do ethologists, such as Lorenz, mean by imprinting on a parent-figure?
b) What observations led Bowlby to suggest that imprinting occurs in human infants? That is, what parallels between human infants and other species did he point to?
"For children to learn, we must praise their correct responses and correct their mistakes." Would Montessori agree? Explain.
What did Werner mean by "microgenesis" and "microgenetic mobility?" Give examples. Discuss some valuable aspects of these concepts.
Piaget's critics charge that he made development appear too slow. Discuss this criticism with respect to either: a) object permanence, b) conservation training, or c) Kamii's teaching methods. Then, describe the Piagetian approach.
Compare conventional and postconventional morality in Kohlberg's theory.
.
More Related Content
Similar to Write java program using linked list to get integer from user and.docx
Program to insert in a sorted list #includestdio.h#include.pdfsudhirchourasia86
* Program to insert in a sorted list */
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function to insert a new_node in a list. Note that this
function expects a pointer to head_ref as this can modify the
head of the input linked list (similar to push())*/
void sortedInsert(struct node** head_ref, struct node* new_node)
{
struct node* current;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->data >= new_node->data)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
/* Locate the node before the point of insertion */
current = *head_ref;
while (current->next!=NULL &&
current->next->data < new_node->data)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
/* BELOW FUNCTIONS ARE JUST UTILITY TO TEST sortedInsert */
/* A utility function to create a new node */
struct node *newNode(int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
new_node->next = NULL;
return new_node;
}
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
/* Drier program to test count function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
struct node *new_node = newNode(5);
sortedInsert(&head, new_node);
new_node = newNode(10);
sortedInsert(&head, new_node);
new_node = newNode(7);
sortedInsert(&head, new_node);
new_node = newNode(3);
sortedInsert(&head, new_node);
new_node = newNode(1);
sortedInsert(&head, new_node);
new_node = newNode(9);
sortedInsert(&head, new_node);
printf(\"\ Created Linked List\ \");
printList(head);
return 0;
}
public class Listnode {
//*** fields ***
private Object data;
private Listnode next;
//*** methods ***
// 2 constructors
public Listnode(Object d) {
this(d, null);
}
public Listnode(Object d, Listnode n) {
data = d;
next = n;
}
// access to fields
public Object getData() {
return data;
}
public Listnode getNext() {
return next;
}
// modify fields
public void setData(Object ob) {
data = ob;
}
public void setNext(Listnode n) {
next = n;
}
}
Thsi below program print out all the varibles in SLL
#include
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Takes head pointer of the linked list and index
as arguments and return data at index*/
int GetNth(struct node* head, int index)
{
struct node* current = head;
int .
Below is a depiction of a doubly-linked list implementation of the bag.docxgilliandunce53776
Below is a depiction of a doubly-linked list implementation of the bag ADT with two sentinels -one at the head and one at the tail. Strict DLink { TYPE value; strict DLink * next; struct DLink * prev;}; strict linked List { int size; struct DLink *frontSentinel; struct DLink *backSentinel;}; Write a function that at first reverses the list and then prints the values of the links in the list from front to back. Don\'t redirect to any other function. You must use assertions if necessary.
Solution
/* Program to reverse a doubly linked list */
#include <stdio.h>
#include <stdlib.h>
/* a node of the doubly linked list */
struct node
{
int data;
struct node *n;
struct node *pr;
};
/* Function to reverse a Doubly Linked List */
void reverse(struct node **head_r)
{
struct node *t = NULL;
struct node *cur = *head_r;
/* swap next and prev for all nodes of
doubly linked list */
while (cur != NULL)
{
t = cur->pr;
cur->pr = cur->n;
cur->n = t;
cur = cur->pr;
}
/* Before changing head, check for the cases like empty
list and list with only one node */
if(t != NULL )
*head_r = t->pr;
}
/* UTILITY FUNCTIONS */
/* Function to insert a node at the beginging of the Doubly Linked List */
void push(struct node** head_r, int new_data)
{
/* allocate node */
struct node* n_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
n_node->data = n_data;
/* since we are adding at the begining,
prev is always NULL */
n_node->pr = NULL;
/* link the old list off the new node */
n_node->n = (*head_r);
/* change prev of head node to new node */
if((*head_r) != NULL)
(*head_r)->pr = n_node ;
/* move the head to point to the new node */
(*head_r) = n_node;
}
/* Function to print nodes in a given doubly linked list
This function is same as printList() of singly linked lsit */
void printList(struct node *node)
{
while(node!=NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
}
/* Drier program to test above functions*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
/* Let us create a sorted linked list to test the functions
Created linked list will be 10->8->4->2 */
push(&head, 2);
push(&head, 4);
push(&head, 8);
push(&head, 10);
printf(\"\ Original Linked list \");
printList(head);
/* Reverse doubly linked list */
reverse(&head);
printf(\"\ Reversed Linked list \");
printList(head);
getchar();
}
.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
C++: Doubly-Linked Lists
The goal of the exercise is to implement a class List of doubly- linked lists.
My goal is to implement the class in a file doubly-linked.cpp.
The class List implements lists using the following structures for list ele- ments:
struct Node { int val ;
Node next;
Node prev; };
Each Node contains a value (an integer) and two pointers: one meant to point to the next element
of the list and one meant to point to the previous element in the list. The class provides the
following methods that you need to implement:
• A constructor and a destructor, with no arguments;
• void insert(int n): insert an integer at the end of the list;
• void reverse(): reverse the list;
• void print(): print the list to cout in the same format as the input (i.e. integers separated by
spaces);
doubly-linked.h
#ifndef __dll__
#define __dll__
#include
using namespace std;
// Basic structure to store elements of a list
struct Node {
int val; // contains the value
Node * next; // pointer to the next element in the list
Node * prev; // pointer to the previous element in the list
};
// Class List
class List {
public:
List(void); // Constructor
~List(void); // Destructor
void insert(int n); // This should insert n in the list
void reverse(void); // This should reverse the list
void print(void); // This shoiuld print the list
private:
Node * first; // Pointer to the first (if any) element in the list
};
#endif
main.cpp
#include
#include \"doubly-linked.h\"
using namespace std;
int main(void){
List l;
int n;
while(cin >> n){
l.insert(n);
}
// Print list as read from cin
l.print();
// Reverse the list and print it
l.reverse();
l.print();
// Reverse again and print it
l.reverse();
l.print();
return 0;
}
Solution
#include
using namespace std;
/* Linked list structure */
struct list {
struct list *prev;
int data;
struct list *next;
} *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class linkedlist {
public:
/* Function for create/insert node at the beginning of Linked list */
void insrt_frnt() {
list *addBeg = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addBeg->data;
if(first == NULL) {
addBeg->prev = NULL;
addBeg->next = NULL;
first = addBeg;
last = addBeg;
cout << \"Linked list Created!\" << endl;
}
else {
addBeg->prev = NULL;
first->prev = addBeg;
addBeg->next = first;
first = addBeg;
cout << \"Data Inserted at the beginning of the Linked list!\" << endl;
}
}
/* Function for create/insert node at the end of Linked list */
void insrt_end() {
list *addEnd = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addEnd->data;
if(first == NULL) {
addEnd->prev = NULL;
addEnd->next = NULL;
first = addEnd;
last = addEnd;
cout << \"Linked list Created!\" << endl;
}
else {
addEnd->next = NULL;
last->next = addEnd;
addEnd->prev = last;
last = addEnd;
cout << \"Data Inserted at the end of the Linked list!\" << endl;
}
}
/* Function for Display Linked list */
void display() {
node = first;
cout << \"List of data in L.
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
Brianca plans to save $5,000, $1,000, and $42,000 a year over the next three years, respectively. How much would you need to deposit in one lump sum today to have the same amount as Brianca three years from now if you both earn 10.9 percent, compounded annually? $36,115 $35,192 $43,282 $41,635 $35,372
.
A)B) C++ program to create a Complete Binary tree from its Lin.pdfanton291
A)
B)
// C++ program to create a Complete Binary tree from its Linked List
// Representation
#include
#include
#include
using namespace std;
// Linked list node
struct ListNode
{
int data;
ListNode* next;
};
// Binary tree node structure
struct BinaryTreeNode
{
int data;
BinaryTreeNode *left, *right;
};
// Function to insert a node at the beginning of the Linked List
void push(struct ListNode** head_ref, int new_data)
{
// allocate node and assign data
struct ListNode* new_node = new ListNode;
new_node->data = new_data;
// link the old list off the new node
new_node->next = (*head_ref);
// move the head to point to the new node
(*head_ref) = new_node;
}
// method to create a new binary tree node from the given data
BinaryTreeNode* newBinaryTreeNode(int data)
{
BinaryTreeNode *temp = new BinaryTreeNode;
temp->data = data;
temp->left = temp->right = NULL;
return temp;
}
// converts a given linked list representing a complete binary tree into the
// linked representation of binary tree.
void convertList2Binary(ListNode *head, BinaryTreeNode* &root)
{
// queue to store the parent nodes
queue q;
// Base Case
if (head == NULL)
{
root = NULL; // Note that root is passed by reference
return;
}
// 1.) The first node is always the root node, and add it to the queue
root = newBinaryTreeNode(head->data);
q.push(root);
// advance the pointer to the next node
head = head->next;
// until the end of linked list is reached, do the following steps
while (head)
{
// 2.a) take the parent node from the q and remove it from q
BinaryTreeNode* parent = q.front();
q.pop();
// 2.c) take next two nodes from the linked list. We will add
// them as children of the current parent node in step 2.b. Push them
// into the queue so that they will be parents to the future nodes
BinaryTreeNode *leftChild = NULL, *rightChild = NULL;
leftChild = newBinaryTreeNode(head->data);
q.push(leftChild);
head = head->next;
if (head)
{
rightChild = newBinaryTreeNode(head->data);
q.push(rightChild);
head = head->next;
}
// 2.b) assign the left and right children of parent
parent->left = leftChild;
parent->right = rightChild;
}
}
// Utility function to traverse the binary tree after conversion
void inorderTraversal(BinaryTreeNode* root)
{
if (root)
{
inorderTraversal( root->left );
cout << root->data << \" \";
inorderTraversal( root->right );
}
}
// Driver program to test above functions
int main()
{
// create a linked list shown in above diagram
struct ListNode* head = NULL;
push(&head, 36); /* Last node of Linked List */
push(&head, 30);
push(&head, 25);
push(&head, 15);
push(&head, 12);
push(&head, 10); /* First node of Linked List */
BinaryTreeNode *root;
convertList2Binary(head, root);
cout << \"Inorder Traversal of the constructed Binary Tree is: \ \";
inorderTraversal(root);
return 0;
}
c)
#include
#include
using namespace std;
template
class bintree
{
bintree *left;
T data;
bintree *right;
public :
bintree()
{
left=right=NULL;
}
void create();
void preorder();
void inorder();
void pos.
In the class we extensively discussed a node class called IntNode in.pdfarjunstores123
In the class we extensively discussed a node class called IntNode in which each linked list node
contains an integer and each node is linked forward to the next element in the list. Implement a
node class called DoublyIntNode in which each node contains an integer number and each node
is linked not only forward to the next element in the list but also backward to the previous
element in the list. Your implementation of DoublyIntNode should adapt and implement all the
methods of IntNode including the following methods:
Constructor for DoublyIntNode
addNodeAfter, removeNodeAfter
getData, setData
getForeLink, setForeLink
getBackLink, setBackLink
listCopy
listCopyWithTail
listLength
listPart
listPosition
listSearch
IntNode and Node classes:
public class IntNode{
private int data;
private IntNode link;
// methods here
}
public class Node {
private E data;
private Node link;
// methods here
}
Solution
program
#include
using namespace std;
struct list
{
struct list *prev;
int data;
struct list *next;
}
*node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class Dlist
{
public:
void insert_beg() {
list *addBeg = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addBeg->data;
if(first == NULL) {
addBeg->prev = NULL;
addBeg->next = NULL;
first = addBeg;
last = addBeg;
cout << \"Linked list Created!\" << endl;
}
else {
addBeg->prev = NULL;
first->prev = addBeg;
addBeg->next = first;
first = addBeg;
cout << \"Data Inserted at the beginning of the Linked list!\" << endl;
}
}
void insert_end() {
list *addEnd = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addEnd->data;
if(first == NULL) {
addEnd->prev = NULL;
addEnd->next = NULL;
first = addEnd;
last = addEnd;
cout << \"Linked list Created!\" << endl;
}
else {
addEnd->next = NULL;
last->next = addEnd;
addEnd->prev = last;
last = addEnd;
cout << \"Data Inserted at the end of the Linked list!\" << endl;
}
}
void display() {
node = first;
cout << \"List of data in Linked list in Ascending order!\" << endl;
while(node != NULL) {
cout << node->data << endl;
node = node->next;
}
node = last;
cout << \"List of data in Linked list in Descending order!\" << endl;
while(node != NULL) {
cout << node->data << endl;
node = node->prev;
}
}
void del()
{
int count = 0, number, i;
node = node1 = node2 = first;
for(node = first; node != NULL; node = node->next)
cout << \"Enter value for the node:\" << endl;
count++;
display();
cout << count << \" nodes available here!\" << endl;
cout << \"Enter the node number which you want to delete:\" << endl;
cin >> number;
if(number != 1)
{
if(number < count && number > 0)
{
for(i = 2; i <= number; i++)
node = node->next;
for(i = 2; i <= number-1; i++)
node1 = node1->next;
for(i = 2; i <= number+1; i++)
node2 = node2->next;
node2->prev = node1;
node1->next = node2;
node->prev = NULL;
node->next = NULL;
node = NULL;
}
else if(number == count)
{
node = last;
last = node->prev;
last->next = NULL;
node = NULL;
}
else
cout << \"Invalid node.
Write a program in C that does the followinga) Builds a simple li.pdfkavithaarp
Write a program in C that does the following:
a) Builds a simple linked list consisting of 10 nodes each of which contains a random integer
between 50 and 100 inclusive. The list is to be built in main() and must be a local variable in
main().
b) Includes a user-defined function named printout(arg) that takes in the head pointer of the
already-built linked list as an argument and prints out the contents of the linked list to the screen,
starting from the head of the list to the tail. See the output below.
Node #0 contains 53
Node #1 contains 78
Node #2 contains 95
. . .
Node #20 contains 100
c) Includes a user-defined function called sum() that adds up the contents of the data members of
each node in the list, and prints out the total as follows:
The sum total of all nodes in this list is
d) Includes a user-defined function called reverse() that takes in the head pointer of the already-
built linked list as an argument and will physically reverse the order of the nodes in the list (i.e.,
the new head will be the old tail and the new tail will be the old head of the list). Use the
function printout() to output its contents now in reverse order. This does NOT mean that it will
be read backwards, but rather, the reversed list will be read from head to tail!
** PLEASE MAKE SURE THIS PROGRAM WORKS IN C LANGUAGE !!
Solution
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* Function to reverse the linked list */
static void reverse(struct node** head_ref)
{
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head_ref = prev;
}
/* Function to push a node */
void push(struct node** head_ref, int new_data)
{
/* allocate node */
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Function to print linked list */
void printList(struct node *head)
{
struct node *temp = head;
int i=0;
while(temp != NULL)
{
printf(\"Node #%d contains %d\ \",i, temp->data);
temp = temp->next;
i++;
}
}
void sum(struct node *head)
{
int sum=0;
struct node *temp = head;
while(temp != NULL)
{
//printf(\"%d \", temp->data);
sum+=temp->data;
temp = temp->next;
}
printf(\"\ The sum total of all nodes in this list is %d\ \",sum);
}
/* Driver program to test above function*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
int i,t;
for(i=0;i<10;i++)
{
// (rand() % 51) generates random number between 0 and 50 adding 50 generates random
number beween 50 and 100 both inclusive
t=(rand() % 51)+50;
push(&head, t);
}
printf(\"Given linked list\ \");
printList(head);
sum(head);
reverse(&head);
printf(\"\ Reversed Linked list \ \");
printList(head);
return 0;
}.
Consider a double-linked linked list implementation with the followin.pdfsales98
Consider a double-linked linked list implementation with the following node: struct Node {int
data; Node *prev; Node *next;} Write a copyList method that is not a member of any class.
The method should take a head pointer and return another pointer. Do not modify the input.
Solution
struct Node {
Node *prev; // previous node
Node *next; // next node
int data; // stored value
};
#include
#include \"List.h\" // std: #include
using namespace std;
typedef DataList ; // std: typedef list Data;
int main() {
Data k;
// back stuff
k.push_back(5);
k.push_back(6);
cout << k.back() << endl;
k.pop_back();
// front stuff
k.push_front(4);
k.push_front(3);
cout << k.front() << endl;
k.pop_front();
// forward iterator
Data::iterator pos;
for (pos = k.begin(); pos != k.end(); ++pos)
cout << *pos << endl;
// output and delete list
while (!k.empty()) {
cout << k.front() << endl;
k.pop_front();
}
k.push_front(5);
k.push_front(6);
// remove and erase
k.remove(5);
pos = k.begin();
k.erase(pos);
k.push_front(5);
k.push_front(6);
// copy constructor
Data l = k;
// assignment operator
Data m;
m = k;
return 0;
}
// List.h
struct Node;
classIterator List;
class List {
public:
typedef ListIterator iterator;
// constructor
List();
// destructor
virtual ~List();
// copy constructor
List(const List& k);
// assignment operator
List& operator=(const List& k);
// insert value in front of list
void push_front(double data);
// insert value in back of list
void push_back(double data);
// delete value from front of list
void pop_front();
// delete value from back of list
void pop_back();
// return value on front of list
double front() const;
// return value on back of list
double back() const;
// delete value specified by iterator
void erase(const iterator& i);
// delete all nodes with specified value
void remove(double data);
// return true if list is empty
bool empty() const;
// return reference to first element in list
iterator begin() const;
// return reference to one past last element in list
iterator end() const;
private:
Node *head; // head of list
};
class ListIterator {
public:
// default constructor
ListIterator() {
i = 0;
}
// construct iterator for given pointer (used for begin/end)
ListIterator(Node *p) {
i = p;
}
// convert iterator to Node*
operator Node*() const {
return i;
}
// test two iterators for not equal
bool operator!=(const ListIterator& k) const {
return i != k.i;
}
// preincrement operator
ListIterator& operator++() {
i = i->next;
return *this;
}
// return value associated with iterator
double& operator*() const {
return i->data;
}
private:
Node *i; // current value of iterator
};
list.cpp
// delete list
static void deleteList(Node *head) {
Node *p = head->next;
while (p != head) {
Node *next = p->next;
delete p;
p = next;
}
delete head;
}
// copy list
static void copyList(const Node *from, Node *&to) {
// create dummy header
to = new Node;
to->next = to->prev = to;
// copy nodes
for (Node *p = from->next; p != from; p = p->next) {
Node *t = new Node;
t.
Please correct my errors upvote Clears our entire .pdfkitty811
Please correct my errors. upvote
/**
* Clears our entire list, making it empty
* Remember: All removal operations should be memory-leak free.
*/
void clear()
{
// Set a pointer to the head of the list
Node<T> *current = head_;
// Loop through each node in the list
while (current != nullptr)
{
Node<T> *next = current->getNext();
delete current;
current = next;
}
// Set head and tail pointers to null and reset the size of the list
head_ = nullptr;
tail_ = nullptr;
size_ = 0;
}
/**
* Insert an element after the node pointed to by the pos Iterator
*
* If the list is currently empty,
* ignore the iterator and just make the new node at the head/tail (list of length 1).
*
* If the incoming iterator is this->end(), insert the element at the tail
*
* Should return an iterator that points to the newly added node
*
* To avoid repeated code, it might be a good idea to have other methods
* rely on this one.
*/
Iterator insert_after(Iterator pos, const T& value) {
}
/**
* Insert a new element after the index pos.
* Should work with an empty list.
*
* Should return an iterator pointing to the newly created node
*
* To reduce repeated code, you may want to simply find
* an iterator to the node at the pos index, then
* send it to the other overload of this method.
*/
Iterator insert_after(size_t pos, const T &value)
{
Iterator it = begin();
for (size_t i = 0; i < pos && it != end(); i++)
{
++it;
}
return insert_after(it, value);
}
/**
* Erase the node pointed to by the Iterators cursor.
*
* If the 'pos' iterator does not point to a valid node,
* throw an std::range_error
*
* Return an iterator to the node AFTER the one we erased,
* or this->end() if we just erased the tail
*/
Iterator erase(Iterator pos)
{
Node<T> *node = pos.node_;
if (node == nullptr || node == head_ || node == tail_)
{
throw std::range_error("Invalid iterator");
}
Node<T> *prevNode = node->prev_;
Node<T> *nextNode = node->next_;
// Updates the next_ pointer of the previous node to point to the next node or updates the head_
pointer
if (prevNode != nullptr)
{
prevNode->next_ = nextNode;
}
else
{
head_ = nextNode;
}
if (nextNode != nullptr)
{
nextNode->prev_ = prevNode;
}
else
{
tail_ = prevNode;
}
Iterator nextIt(nextNode, head_, tail_);
delete node;
return nextIt;
}
/**
* Add an element just after the one pointed to by the 'pos' iterator
*
* Should return an iterator pointing to the newly created node
*/
Iterator push_after(Iterator pos, const T &value)
{
Node<T> *node = pos.node_;
if (node == nullptr)
{
throw std::range_error("Invalid iterator");
}
Node<T> *nextNode = node->next_;
Node<T> *newNode = new Node(value, node, nextNode);
node->next_ = newNode;
if (nextNode != nullptr)
{
nextNode->prev_ = newNode;
}
else
{
tail_ = newNode;
}
return Iterator(newNode, head_, tail_);
}
/**
* Add a new element to the front of our list.
*/
void push_front(const T &value)
{
Node<T> *new_node = new Node<T>(value, nullptr, head_);
if (head_ == nullptr)
{
tail_ = new_node;
}
else
{
head_->setPrevious(new.
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
Using the provided table interface table.h and the sample linked list code linkedList.c, complete
an implementation of the Table ADT. Make sure that you apply the concepts of design by
contract (DbC) to your implementation.
Once you have fully implemented the table, create a main.c file that implements a testing
framework for your table.
Your table implementation must ensure that values inserted are unique, and internally sorted
within a linked list.
table.h
linkedList.c
Solution
khsdg
#include
#include
typedef enum BOOL { false, true } bool;
// Linked list node definition
typedef struct Node node;
struct Node
{
int number;
node *next;
};
static node *top = NULL;
// used to track where we are for the list traversal methods
static node *traverseNode = NULL;
// \"destroy\" will deallocate all nodes in a linked list object
// and will set \"top\" to NULL.
void destroy()
{
node *curr = top;
node *temp = NULL;
while ( curr != NULL )
{
// flip order to see it blow up...
temp = curr;
curr = curr->next;
free( temp );
}
top = NULL;
}
// \"build\" will create an ordered linked list consisting
// of the first \"size\" even integers.
void build( int size )
{
node *newNode = NULL;
int i = 0;
// make sure we don\'t have a list yet
destroy();
for ( i=size ; i>0 ; i-- )
{
newNode = malloc( sizeof( node ) );
newNode->number = i*2;
newNode->next = top;
top = newNode;
}
}
// starts a list traversal by getting the data at top.
// returns false if top == NULL.
bool firstNode( int *item )
{
bool result = false;
if ( top )
{
*item = top->number;
traverseNode = top->next;
result = true;
}
return result;
}
// gets the data at the current traversal node and increments the traversal.
// returns false if we\'re at the end of the list.
bool nextNode( int *item )
{
bool result = false;
if ( traverseNode )
{
*item = traverseNode->number;
traverseNode = traverseNode->next;
result = true;
}
return result;
}
// \"print\" will output an object\'s entire linked list
// to the standard output device -- one \"number\" per line.
void print()
{
int value;
if ( firstNode( &value ) )
{
do
{
printf( \"%d\ \", value );
} while ( nextNode( &value ) );
}
}
int main( int argc, char *argv[] )
{
build( 10 );
print();
destroy();
build( 5 );
build( 20 );
print();
destroy();
return 0;
}.
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
C++ problem
Part 1: Recursive Print (40 pts)
Please write the recursive List reverse print function, whose iterative version we wrote in class.
Below are the function signatures for the functions you are going to need:
public:
/**Additional Operations*/
void print_reverse();
//Wrapper function that calls the reverse helper function to print a list in reverse
//prints nothing if the List is empty
private:
void reverse(Nodeptr node);
//Helper function for the public printReverse() function.
//Recursively prints the data in a List in reverse.
Why do we need the private helper function here?
Since we are going to be reversing our list node by node, in a recursive fashion, we want to pass
a one node at a time to our reverse function.
However, since our nodes are private, we cannot access them if we call the function inside of
main.
Add these function signatures to your List.h file along with your other function prototypes inside
the class definition.
Make sure that you place the reverse function inside the private portion of your List class
definition and the print_reverse function prototype to the public portion of your List class
definition.
Now, implement these two functions inside of List.h, under your section for additional
operations.
Important: Test each function carefully inside of your ListTest.cpp to make sure that it is
working properly.
Part 2: Adding an Index to Your List Nodes (20 pts)
Next, you will add the following functions to your List.h
/**Accessor Functions*/
int get_index();
//Indicates the index of the Node where the iterator is currently pointing
//Nodes are numbered from 1 to length of the list
//Pre: length != 0
//Pre: !off_end()
...
int List::get_index()
{
//Implement the function here
}
/**Manipulation Procedures*/
void scroll_to_index(int index);
//Moves the iterator to the node whose index is specified by the user
//Pre: length != 0
...
void scroll_to_index(int index)
{
//Implement function here
}
Part 3: Implementing Search as Part of Your List (40 pts)
Now, we are going to add two search functions to our List so that we can search for elements in
our List.
The first of these functions is going to be a simple linear search function.
You will need to add the following function prototype and function definition to your List.h:
/**Additional Operations*/
int linear_search(listitem item);
//Searchs the list, element by element, from the start of the List to the end of the List
//Returns the index of the element, if it is found in the List
//Returns -1 if the element is not in the List
//Pre: length != 0
...
int List::linear_search(listitem item)
{
//Implement the function here
}
You are also going to add a function to perform recursive binary search on your List.
You will need to add the following function prototype and function definition to your List.h:
int binary_search(int low, int high, listitem item);
//Recursively searchs the list by dividing the search space in half
//Returns the index of the element, if it is fo.
Write an algorithm that reads a list of integers from the keyboard, .pdfArrowdeepak
Write an algorithm that reads a list of integers from the keyboard, creates
a list of them using linked list implementation, and prints the result
Solution
/*
Algorithm:
Implementation of linked list.
Create a node type class which will hold an integer and next pointer to point to another node.
Create a constructor which will construct an object of type node with the integer type data as the
only parameter
and initializing next pointer to NULL.
Create LinkedList class which will only have head pointer.
Create a constructor which will initialize this head pointer to NULL.
Create a append method which will recieve an input of type integer from the user and append it
to LinkedList
using below steps:
1.Create a Node type object.
1.IF head is NULL assign a Node type object created in 1st step.
2.IF head is not NULL then traverse to the end of the linked list till you found a Node which has
next pointer
set to NULL.
3.Add Node type object created in first step to the next pointer of last node.
Create a print method which will traverse the list from the head of the linked list to the last
node(Node
with next pointer NULL) and while traversing it will keep printing the node data.
Get the userinput:
Ask user for integer continously till user input -1 and append all the integers to the linked list.
*/
PROGRAM:
#include
using namespace std;
class Node
{
public:
int data;
Node *next;
Node(int data)
{
this->data = data;
this->next = NULL;
}
};
class LinkedList
{
private:
Node *head;
public:
LinkedList()
{
head = NULL;
}
void addToFront(int data)
{
Node *temp = new Node(data);
if(head == NULL)
head = temp;
else
{
temp->next = head;
head = temp;
}
}
void append(int data)
{
Node *temp = new Node(data);
Node *current = head;
if(current == NULL)
{
head = temp;
return;
}
while(current->next != NULL)
{
current = current->next;
}
current->next = temp;
}
void print()
{
Node *current = head;
if(current == NULL)
cout << \"No element in list. \ \";
while(current != NULL)
{
cout << current->data << \" \";
current = current->next;
}
cout << endl;
}
void deleteLinkedList()
{
Node *prev;
Node *current = head;
while(current!=NULL)
{
prev = current;
current = current->next;
delete prev;
}
}
void deleteLastNode()
{
Node *current = head;
Node *prev = NULL;
if(current == NULL)
return;
while(current->next != NULL)
{
prev = current;
current = current->next;
}
if(prev == NULL)
{
delete current;
head = NULL;
}
else
{
prev->next = NULL;
delete current;
}
}
~LinkedList()
{
deleteLinkedList();
}
};
int main()
{
LinkedList list;
int data;
while(1)
{
cout << \"Enter the integer(-1 to Quit) : \";
cin >> data;
if(data==-1)
break;
list.append(data);
}
cout << \"Content of LinkedList is : \";
list.print();
return 0;
}
OUTPUT:
Enter the integer(-1 to Quit) : 1
Enter the integer(-1 to Quit) : 2
Enter the integer(-1 to Quit) : 3
Enter the integer(-1 to Quit) : 4
Enter the integer(-1 to Quit) : -1
Content of LinkedList is : 1 2 3 4.
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
Data Structures in C++
I am really new to C++, so links are really hard topic for me. It would be nice if you can provide
explanations of what doubly linked lists are and of some of you steps... Thank you
In this assignment, you will implement a doubly-linked list class, together with some list
operations. To make things easier, you’ll implement a list of int, rather than a template class.
Solution
A variable helps us to identify the data. For ex: int a = 5; Here 5 is identified through variable a.
Now, if we have collection of integers, we need some representation to identify them. We call it
array. For ex: int arr[5]
This array is nothing but a Data Structure.
So, a Data Structure is a way to group the data.
There are many Data Structures available like Arrays, Linked List, Doubly-Linked list, Stack,
Queue, etc.
Doubly-Linked list are the ones where you can traverse from the current node both in left and
right directions.
Why so many different types of Data Structures are required ?
Answer is very simple, grouping of data, storage of data and accessing the data is different.
For example, in case of Arrays we store all the data in contiguous locations.
What if we are not able to store the data in contiguous locations because we have huge data.
Answer is go for Linked List/Doubly-Linked list.
Here we can store the data anywhere and link the data through pointers.
I will try to provide comments for the code you have given. May be this can help you.
#pragma once
/*
dlist.h
Doubly-linked lists of ints
*/
#include
class dlist {
public:
dlist() { }
// Here we are creating a NODE, it has a integer value and two pointers.
// One pointer is to move to next node and other to go back to previous node.
struct node {
int value;
node* next;
node* prev;
};
// To return head pointer, i.e. start of the Doubly-Linked list.
node* head() const { return _head; }
// To return Tail pointer, i.e. end of the Doubly-Linked list.
node* tail() const { return _tail; }
// **** Implement ALL the following methods ****
// Returns the node at a particular index (0 is the head).
node* at(int index){
int cnt = 0;
struct node* tmp = head();
while(tmp!=NULL)
{
if (cnt+1 == index)
return tmp;
tmp = tmp->next;
}
}
// Insert a new value, after an existing one
void insert(node *previous, int value){
// check if the given previous is NULL
if (previous == NULL)
{
printf(\"the given previous node cannot be NULL\");
return;
}
// allocate new node
struct node* new_node =(struct node*) malloc(sizeof(struct node));
// put in the data
new_node->data = new_data;
// Make next of new node as next of previous
new_node->next = previous->next;
// Make the next of previous as new_node
previous->next = new_node;
// Make previous as previous of new_node
new_node->prev = previous;
// Change previous of new_node\'s next node
if (new_node->next != NULL)
new_node->next->prev = new_node;
}
// Delete the given node
void del(node* which){
struct node* head_ref = head();
/* base case */
if(*head_ref == NUL.
Program In C You are required to write an interactive C program that.pdfamitbagga0808
Program In C You are required to write an interactive C program that prompts the user for
commands, accepts commands from the keyboard (stdin) and executes those commands. When a
command requires output, it must be written to stdout. The program must continue to accept and
process commands until the user types the end command ourput, it must be writen to stdout. The
program must continue to accept and proces.commands The program deals with linked lists.
Each node of such a list contains a string of length at most 10, a positive integer (i.e., an integer
value 2 1) and a pointer to the next node of the list. For any node, the string and the integer
stored in that node will be referred to as the symbol and count for that node respectively. At all
times, the list must satisfy the following two important properties. 1. The symbols appearing in
the list are all distinct; that is, no two nodes have the same symbol. 2. When the list is scanned
from left to right, the counts must be in non-increasing order. An example of such a linked list is
shown below. Search 4 Maxval4 begin/ Loop head
Solution
/**********************************************/
/****** NAMES ******************** COMMANDS ***/
/* Insert Command : ins str */
/* Delete Command : del str */
/* Forced Delete Command : fde val */
/* Print Statistics Command : pst */
/* Print List Command : prl */
/* Print using Count Range Command: pcr v1 v2 */
/* Print Prefix Command : ppr str */
/* Print Suffix Command : psu str */
/* End Command : end */
/***********************************************/
#include
#include
#include
#define CSIZE 4
#define SSIZE 11
/* Struct for each node in the linked list */
struct node
{
int count;
char symbol[SSIZE];
struct node *next;
};
struct node *head;
/* Prototypes for the functions */
void insert(char *);
void delete(char *);
void forced_delete(int value);
void print_stats();
void print_list();
void print_count(int, int);
void print_prefix(char pre[]);
void print_suffix(char suf[]);
void sort_list();
/****************
** Main Method **
****************/
int main(void)
{
int count;
char symbol[SSIZE];
char cmd[CSIZE];
int v1;
int v2;
/* Enter commands */
printf(\"Command? \"); fflush(stdout);
scanf(\"%s\", cmd);
/* Check for command*/
while(strcmp(cmd,\"end\") != 0)
{
/* check which function to use */
if(strcmp(cmd,\"ins\") == 0) { scanf(\"%s\", symbol); insert(symbol); }
if(strcmp(cmd,\"del\") == 0) { scanf(\"%s\", symbol); delete(symbol); }
else if(strcmp(cmd,\"fde\")==0){scanf(\"%d\",&count); forced_delete(count); }
if(strcmp(cmd,\"pst\") == 0) { print_stats();}
if(strcmp(cmd,\"prl\") == 0) { print_list(); }
if(strcmp(cmd,\"pcr\") == 0) { scanf(\"%d %d\",&v1,&v2); print_count(v1,v2); }
if(strcmp(cmd,\"ppr\") == 0) { scanf(\"%s\", symbol); print_prefix(symbol);}
if(strcmp(cmd,\"psu\") == 0) { scanf(\"%s\", symbol); print_suffix(symbol);}
printf(\"Command? \"); fflush(stdout);
scanf(\"%s\", cmd);
}// End of While Loop
return 0;
}// End of main method
/*********.
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(" ".
Similar to Write java program using linked list to get integer from user and.docx (20)
Please complete the assignment listed below.Define and explain, us.docxajoy21
Please complete the assignment listed below.
Define and explain, using at least five sentence or on-task bullet notes for each. Each answer earns up to five points. For each answer, please make five different substantive points, earning one point each.
Transnational corporation
Gentrification
Renewable resources
Desertification
Photochemical smog
Biodiversity
Barriers to migration
Hierarchical diffusion
Militant fundamentalism
Urbanization
Eastern European cities
Hazardous waste
The Endangered Species Act
Subsidence
Water Quality
Deforestation
Wetlands
Central place theory
Soil degradation
Hydraulic fracturing (fracking)
Wind power
Oil sands
Models of urban form
Hinterland
Agglomeration economies
.
Please cite sources for each question. Do not use the same sources f.docxajoy21
Please cite sources for each question. Do not use the same sources for each question. Minimum of 2 resources and 300 words.
Briefly contrast the views of Locke and Rousseau on how children develop.
a) What do ethologists, such as Lorenz, mean by imprinting on a parent-figure?
b) What observations led Bowlby to suggest that imprinting occurs in human infants? That is, what parallels between human infants and other species did he point to?
"For children to learn, we must praise their correct responses and correct their mistakes." Would Montessori agree? Explain.
What did Werner mean by "microgenesis" and "microgenetic mobility?" Give examples. Discuss some valuable aspects of these concepts.
Piaget's critics charge that he made development appear too slow. Discuss this criticism with respect to either: a) object permanence, b) conservation training, or c) Kamii's teaching methods. Then, describe the Piagetian approach.
Compare conventional and postconventional morality in Kohlberg's theory.
.
Please choose one of the following questions to answer for this week.docxajoy21
Please choose one of the following questions to answer for this week's assignment. When you respond to your fellow classmates this week, please choose someone who answered a different question than your own. This will help you familiarize yourself with more of the material. Remember, you need to post at least three responses to receive full credit for this assignment.
1. The French revolutionaries claimed that they were inspired by the Enlightenment
philosophes
. Would the
philosophes
we studied back in Week 2 have approved of how the Revolution started? What about how it developed through the 1790s?
2. In his
Reflections on the Revolutions in France,
British member of Parliament Edmund Burke predicted the Terror. Was this a lucky guess on his part or were the seeds of of the Terror part of the Revolution from the beginning? Why?
3. The French Revolution had a profound impact on the world, not just within the borders of France. Why were some nations willing to accept its gains-at least, partially-while others resisted them? Which country do you think was the most unwilling to accept the new ideas of
liberte,
e
galite,
and
fraternite
? Other than France, which was most willing to embrace the Revolutionary ideals? Why?
4. Although no historian doubts the importance of the reign of Napoleon in European (and even world) history, they do argue over the interpretation of these events. For example, they are torn on the role Napoleon played in the Revolution. Some argue that he continued the spirit of the Revolution, despite creating an Empire. Others believe he murdered it. Some include Napoleon's reign as a stage of the actual Revolution, while others consider it its own separate event. What do you think? Do you think Napoleon continued and spread the Revolution? Or do you think he destroyed its ideals when creating his empire? Do you think his reign should qualify as a separate historical event from the Revolution? Or was it simply another stage in a long process?
.
Please check the attachment for my paper.Please add citations to a.docxajoy21
Please check the attachment for my paper.
Please add citations to all paragraphs.
Also, please check the paper for plagiarism and please add two more pages on (Social Media & In person Communication) to make it fit the essay so far.
And please use 5 more sources in the paper. (1 Article, 1 Book, 1 Encyclopedia, 1 Newspaper and 1 magazine).
Finally, please correct all the grammar mistakes in the first 3 pages.
And please get rid of the first person used. (I,we etc...)
.
Please answer to this discussion post. No less than 150 words. Refer.docxajoy21
Please answer to this discussion post. No less than 150 words. Reference and APA style needed. Please no plagiarism. Similarity is <20%. Thanks
The most interesting thing about this chapter is that it helps people and scholars to develop skills to influence strategy in nowadays changing healthcare environment. The topic also contributes an extensive range of themes in strategies and politics, offering more complete contextual that can be in other policies textbook in the market (Mason, Leavitt, & Chaffee, 2013). The topics also entail up-to-date updates concerning conflict organization, health economics, politicization, use of media as well as working with societies for change. Reviewed copy take account of new supplement with coverage of advanced reasonably priced care act. According to this perceptions and strategies, every individual will be equipped and ready to play a leadership role under four spheres where nurses are governmentally efficient, the workstation, government, specialized organization as well as the community (American Nurses Association, 2010). The topic has helped me to know more of nursing and healthcare policies and politics.
In thus, have understood that the concept of nursing policies influences can be defined as a nursing ability to have active, effective on decision making as well as affairs connected to health care by use of power, support, and strategy capability, and establishing or strengthening images. The nursing policy and politics within a healthcare connect to my clinical practices because as a nurse, I should view myself as a professional with the ability and being responsible for influencing recent and forthcoming health care conveyance system. But to attain this, there must be the presence of policies that define and assimilate suitable standards for healthcare delivery as well as addressing essential conditions for that care to happen.
References
American Nurses Association. (2010).
Nursing's social policy statement: The essence of the profession
. Nursesbooks. org.
Mason, D. J., Leavitt, J. K., & Chaffee, M. W. (2013).
Policy and Politics in Nursing and Healthcare-Revised Reprint
. Elsevier Health Sciences.
.
Please attach Non-nursing theorist summaries.
Jigsaw/Executive Summary Grading Criteria
Albert Bandura: Self-Efficacy
Points Possible
Your Points
Summary Paper
Introduction/Conclusion
2
History/Origins of Theory
3
Major Precepts of Theory
Current Application(s) of Theory
Mechanics
Grammar/form/spelling/punctuation/ Logical flow/readability/APA format
3
Citations and references
2
Total Points
10
.
Please answer the question .There is no work count. PLEASE NUMBER .docxajoy21
Please answer the question .There is no work count. PLEASE NUMBER THE ANSWERS.
1-How does the value of individual freedom effect the ethics of our American society differently than the value of family and religious loyalty?
What are some other values of contemporary American society?
How are they in conflict with the values of the 1950's?
Is one set of values superior to another?
Why?
2-Islam means, at its root, surrender.
How does Islamic belief and practice reflect the importance of surrendering to Allah?
3-What do you think about this focus on prayer?
What is the standard of prayer in Judaism?
What about in Christianity?
What about in your own life?
Are you humbled and challenged by the knowledge that Muslims stop 5 times to pray?
4-Do you think the call to prayer is a call to obedience or a reminder for devotion?
5-Please answer this question and discuss the implications, probe for assumptions, draw out evidence and clarify perspectives.
What was the influence of Islam on the arts and sciences in its Golden Age, which is when Europe was experiencing the Medieval Period, sometimes called the Dark Ages?
6a- You mention the art form of mosaic (you called it "geometric pieces") and I want to draw the class' attention to the idea of unity in diversity within this art form.
First, the main theological point of Islam is that Allah is one.
As the Muslim scientists and artists searched to make discoveries in their given fields of study, they were constantly looking for the unity of Allah in the diversity of the creation.
The artist brought out that unity in mosaic and in textiles.
The mosaic is a pattern that is derived by putting thousands of small colored stones together to make one design.
The individual pieces of stone lose their importance within the whole, but without each piece the whole would not be complete.
So their concept of God came through in their art.
6b-How else did the Muslims bring out unity in diversity?
7a-Because they were prohibited from figures in art, the Muslims developed other art forms and calligraphy is one of those art forms.
They believed that the words of the Qur'an were beautiful (to hear and for life) so they started to write them in a beautiful way and thus calligraphy developed.
Art is one of those things that cannot be totally squelched.
If you contain an artist in one area, their emotion will burst forth in another area.
7b What do you think about the Muslims' use of calligraphy?
The Muslim religion started very rapidly.
8--Class, Based on the information about Muhammad and the early spread of Islam, what do you think was the most important factor in the amazing way that Islam grew so quickly?
.
Please answer the following questions. Please cite your references..docxajoy21
Please answer the following questions. Please cite your references.
According to Section I readings, Democracy: what it is and what it is not? (15 points) (See attached PDF)
Is the U.S. a democratic country? Has your view/opinion changed or unchanged now comparing to your answer at the beginning of the class? (15 points)
What does democracy mean to you personally? What will you do/participate/take action to ensure/protect your definition of democracy? (15 points)
Has the United States been a positive or negative influence on global democracy? (15 points)
Identify yourself as either a municipal, state or federal lawmaker, discuss your action/plan for democracy in the United States and her role as it pertains to the spread of democracy and democratic values throughout the world in the 21
st
Century. (40 points)
.
Please answer the following questions.1. 1. Are you or.docxajoy21
Please answer the following questions.
1.
1.
Are you or your immediate supervisor involved with staffing decisions?
If so, describe how staffing forecasts are prepared.
2.
2.
Does your organization use a flexible or a static budget?
Explain and provide examples.
Note: I work at a hospital as a psychiatric technician
.
Please answer the following question with 200-300 words.Q. Discu.docxajoy21
Please answer the following question with 200-300 words.
Q. Discuss why Hurston's assertions in "Characteristics of Negro Expression" would have been frowned upon by middle and upper class blacks.
Source:
Zora Neale Hurston -
"Characteristics of Negro Expression"
Please don't forget to include at least one quote from the passage.
.
Please answer the following question Why do you think the US ha.docxajoy21
Please answer the following question:
Why do you think the US has such a high homicide rate compared to other Western countries? What would you do to change that?
The paper needs to be 3-4 pages long, 12 point font, Times New Roman, and double spaced. The paper needs to be in
APA format. All sources must be cited.
Due on April 7, 2017 @ 12:30pm.
Anything after 12:30pm will not be accepted.
.
Please answer the following questions. Define tunneling in the V.docxajoy21
Please answer the following questions.
Define tunneling in the VPN environment and explain the difference between voluntary and compulsory tunnels.
How does the VPN technology provides security to a corporate network? You may also choose to compare two or more VPN technologies.
Consider the VPN technologies studied in this session, including IPSec in the Tunnel mode, L2TP over IPsec, PPTP and SSL/TLS VPN. Which one would you choose for your company? Can you discuss its advantages and its weakness or drawbacks? Do you know some products that are based on that technology?
Discuss the specific techniques for securing the remote client and the remote access server and the common concerns of each.
.
Please answer the following questions1. How can you stimulate the.docxajoy21
Please answer the following questions:
1. How can you stimulate the brain development of an infant?
2. How do parents cope with the growing autonomy of toddlers and what should be done about temper tantrums?
3. How do children in these stages of development change the life style of their parents?
Observation:
Have a conversation with the parent of a toddler. What are the differences of dealing with an infant and a toddler?
.
Please answer the following questions very deeply and presicely .docxajoy21
Please answer the following questions very deeply and presicely :
"Ziff"
!)
As Ziff define artwork, what do you think would consider as an artwork, and who do you think is capable of deciding if the work is art or not?
"Danto"
2) Why do you think Danto compares Socrates and Hamlet in the beginning? Do you feel as if it was an imitation of nature? How would you describe the word "art" with these two philosophers?
* The answer should be (4-8 sentences)
.
Please answer the following questions in an informal 1 ½ - 2-page es.docxajoy21
Please answer the following questions in an informal 1 ½ - 2-page essay:
Describe Hubert’s characterization of white society in New York City during the Harlem Renaissance.
What does this essay reveal about black culture in Harlem?
Why does Hubert describe the Harlem Renaissance as “the golden age for Negro writers, artists, and musicians?”
Black writer Alain Locke used the term “New Negro” to describe individuals such as Hubert. What did that mean?
Please conclude your essay with at least one question for discussion. Choose a question that you think will both enlighten and enliven your discussion section.
.
Please answer the following questions in a response of 150 to 200 wo.docxajoy21
Please answer the following questions in a response of 150 to 200 words each, and submit your responses in a Word attachment no later than Sunday of this week at 11:59 p.m. EST.
Discuss the reasons for the Iranian hostage crisis in 1979, and how that has impacted US-Iranian relations since.
Examine the motives of both the United States and the Soviet Union during the Cold War. Provide at least two examples in which these motives led to potential conflict between the two superpowers and/or their proxies (smaller nations in their respective spheres of influence).
Evaluate the assumption that the East European revolutions of 1989-90 that led to the breakup of the Warsaw Pact were a direct cause for the collapse of the Soviet Union. To what extent did these events influence the latter? Could the USSR have relinquished control of Eastern Europe yet remained intact?
.
Please answer these questions regarding the (TILA) Truth in Lending .docxajoy21
Please answer these questions regarding the (TILA) Truth in Lending Act.
1-Did the legislation or regulation solve the problem(s)? How?
2-Who were the major stakeholders?
The answers need to be complete, through and supported by evidence.
The length should as much as needed to answer the questions but not less than three quarters of a page for each question.
.
Please answer the following question pertaining to psychology. Inc.docxajoy21
Please answer the following question pertaining to psychology.
Include references/cites
at least 175 words each question.
1. 12
Despite much effort, a definition of personality has been elusive. Why do you think this is the case? How does this influence the relationship between personality theory and personality assessment?
13
What are the differences in test construction between the Minnesota Multiphasic Personality Inventory (MMPI) and the NEO Personality Inventory? Which do you think is more valid? Explain your responses.
16
How are assessments used in the workplace? How can assessments be misused in the workplace?
Analyze the relationship between the major theories of personality and assessments of personality.
Evaluate the strengths and weaknesses of personality assessment methods.
Describe the application of psychological assessments in the workplace.
.
Please answer the following questions in a response of 250 to 300 .docxajoy21
Please answer the following questions in a response of
250 to 300 words each
, and submit your responses in a Word attachment no later than Sunday of this week at 11:59 p.m. EST.
Identify the causes, key battles, and outcome of World War II in both Europe and the Pacific.
Identify the causes of the Cold War, and explain whether you think the Cold War was inevitable or not following World War II. How did the conflict between communist and non-communist powers manifest in China and Korea?
Pollard, E., Rosenberg, C., & Tignor, R. (2015). Worlds Together Worlds Apart. From 1000 CE to the Present (1st ed., Vol. 2). New York, NY: W.W. Norton & Company.
.
Please answer the three questions completly. I have attached the que.docxajoy21
Please answer the three questions completly. I have attached the questions in excel where they need to be answered.
1)
XYZ Company had three defined benefit plans with the following information:
12 Points
Plan 1
Plan 2
Plan 3
Expected Payment over next year
3,500,000
3,500,000
3,500,000
Fair Value of Plan Assets
5,000,000
6,000,000
3,000,000
Projected Benefit Obligation
7,000,000
5,500,000
4,500,000
Record the over/(under) funded status of each plan. Then determine the balance sheet presentation based on the over/(under) funded status. (Input an amount in each yellow cell. If zero, input zero.)
Plan 1
Plan 2
Plan 3
Over/ (Under) Funded Status
Noncurrent Asset
Current Liability**
Noncurrent Liability
** Think about the expected payment over the next year compared to the Plan Assets available.
2)
XYZ Company received the following information from its actuary team for the
10 points
year pertaining to one of its defined benefit plans:
Service Cost
120,000
Interest on Projected Benefit Obligation
55,000
Expected Return on Plan Assets
30,000
Amortization of Prior Service Cost
15,000
Amortization of Actuarial Gain
10,000
Calculate the Pension Expense for the year (show all items included in the calculation):
3)
At the end of year, XYZ Corporation had the following pension related information in addition to the above information:
12 points
12/31/X1
12/31/X2
Fair Value of Plan Assets
405,000
505,000
Projected Benefit Obligation
1,065,000
1,035,000
Funded Status
(660,000)
(530,000)
Record the Necessary Journal Entries:
Entry to record Service Cost, Interest Cost and Return on Plan Assets:
Account Name:
Debit
Credit
Amortization of Prior Service Cost and/or Actuarial Losses:
Account Name:
Debit
Credit
Amortization of Actuarial Gains:
Account Name:
Debit
Credit
4)
a) Identify a US Company that offers a Defined Benefit Plan and review the 10K information for 2016 of the identified company and provide a brief analysis based on footnotes related to the plan.
3 points
b) Include screenshots to report the Funded Status and Pension Expense information for the selected plan.
1 Points
c) Record the associated journal entries based on the screenshots for that company.
12 points
Entry to record Service Cost, Interest Cost and Return on Plan Assets:
Account Name:
Debit
Credit
Amortization of Prior Serv.
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.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Write java program using linked list to get integer from user and.docx
1. Write java program using linked list to get integer from user
and count even and odd number .
Write java program using linked list to get integer from user
and count even and odd number .
Solution
// Java program to segregate even and odd nodes in a
// Linked List
class LinkedList
{
Node head; // head of list
/* Linked list Node*/
class Node
{
int data;
Node next;
Node(int d)
{
data = d;
next = null;
2. }
}
void segregateEvenOdd()
{ int count=0;
Node end = head;
Node prev = null;
Node curr = head;
/* Get pointer to last Node */
while (end.next != null)
end = end.next;
Node new_end = end;
// Consider all odd nodes before getting first eve node
while (curr.data %2 !=0 && curr != end)
{
new_end.next = curr;
curr = curr.next;
new_end.next.next = null;
new_end = new_end.next;
count=curr.data;
count++;
}
System.out.println("The count"+count);
// do following steps only if there is an even node
if (curr.data %2 ==0)
{
3. head = curr;
// now curr points to first even node
while (curr != end)
{
if (curr.data % 2 == 0)
{
prev = curr;
curr = curr.next;
}
else
{
/* Break the link between prev and curr*/
prev.next = curr.next;
/* Make next of curr as null */
curr.next = null;
/*Move curr to end */
new_end.next = curr;
/*Make curr as new end of list */
new_end = curr;
/*Update curr pointer */
curr = prev.next;
}
}
}
/* We have to set prev before executing rest of this code */
4. else prev = curr;
if (new_end != end && end.data %2 != 0)
{
prev.next = end.next;
end.next = null;
new_end.next = end;
}
}
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(int new_data)
{
/* 1 & 2: Allocate the Node &
Put in the data*/
Node new_node = new Node(new_data);
/* 3. Make next of new Node as head */
new_node.next = head;
/* 4. Move the head to point to new Node */
head = new_node;
}
// Utility function to print a linked list
void printList()
{
Node temp = head;
5. while(temp != null)
{
System.out.print(temp.data+" ");
temp = temp.next;
}
System.out.println();
}
/* Drier program to test above functions */
public static void main(String args[])
{
LinkedList llist = new LinkedList();
llist.push(11);
llist.push(10);
llist.push(8);
llist.push(6);
llist.push(4);
llist.push(2);
llist.push(0);
System.out.println("Origional Linked List");
llist.printList();
llist.segregateEvenOdd();
System.out.println("Modified Linked List");
llist.printList();
}
}