- Accounts(memberID, fName, 1Name, email, creditCardNo, password) - CreatesProfiles
(memberID, name, gender, dob ) - pGenres (memberID, name, genre) - Movies ( movieID, title,
yearOfRelease, lengthInMinutes, avgRating) - MGenres ( movieID, genre ) - Streams ( movieID,
memberID, name, rating, dateTimeWatched) - Directors ( dID, fName, 1Name, dob) - Directs
(movieID, dID) - Actors (aID, fName, 1Name, gender) - Casts ( movieID, aID, role) The primary
keys are underlined. The referential integrity constraints are as follows: - the column memberID of
relation CreatesProfiles that references table Accounts, - the columns memberID and name of
relation pG Genres that references table CreatesProfiles, - the column movieID of relation
MGenres that references table Movies, - the column movieID of relation Streams that references
table Movies, - the columns memberID and name of relation Streams that references table
CreatesProfiles, - the column movieID of relation Directs that references table Movies, - the
column dID of relation Directs that references table Directors, - the column movieID of relation
Casts that references table Movies, and - the column alD of relation Casts that references table
Actors. The following query is intended to list the ID of directors for Action films. However, this
query does not work properly. Briefly explain why: and show the corrected SQL query SELECT
DISTINCT dID FROM MGenres M, Directs D ON (M.movieID = D.movieID) WHERE genre =
'Action';.
include ltinitializer_listgt include ltiostreamgt .pdficonsystemsslm
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <utility>
/************************************************************/
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
// TODO
// <->| 1 |<->| 2 |<->| 3 |<->| 4 |<->| 5 |<->| 6 |<->
// ^ ^
// begin end
//
// becomes
//
// <->| 1 |<->| 6 |<->
//
// begin and end do not need to change at all
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
// TODO
// this
// v
// <->| 1 |<->| 6 |<-> <->| 2 |<->| 3 |<->| 4 |<->
// ^ ^
// first last
//
// becomes
// this
// v
// <->| 1 |<->| 2 |<->| 3 |<->| 4 |<->| 6 |<->
// ^ ^
// first last
//
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};.
include ltinitializer_listgt include ltiostreamgt .pdfadisainternational
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <utility>
/************************************************************/
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
// TODO
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
// TODO
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};
Please complete the implementation of the missing part marked TODO.
// node insertion/removal [5] static Node:: unhook_range (Node* first, Node* last) [3] When first ==
last (single element) [2] When first != last [5] Node: :hook_range (Node* first, Node* last) [3] When
first != last [2] When first == last (single element).
include ltinitializer_listgt include ltiostreamgt .pdfabidtelecom
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <utility>
/************************************************************/
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
// TODO
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
// TODO
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};
Please complete the implementation of the missing part marked TODO..
tested on eclipseDoublyLinkedList class.pdfshanki7
//tested on eclipse
/*************DoublyLinkedList class*******************/
public class DoublyLinkedList {
/*Data member variable declaration*/
private Node head;
private int count;
/**default constructor*/
public DoublyLinkedList() {
/*Initializing variable*/
head=null;
count =0;
}
/*Insert at beginning in doubly linked list*/
public void insertBeginning(String name){
/*checking head is null then we will add node at head*/
if(head==null){
head=new Node(name, null, null);
count++;
}else{
/*else create temp node and setting next to head
* and then making temp to head*/
Node temp=new Node(name,null,null);
temp.setNext(head);
head.setPrev(temp);
head=temp;
count++;
}
}
public void printList(){
Node temp=head;
/*Printing element of doubly list*/
while(temp!=null){
System.out.println(temp.getData());
temp=temp.getNext();
}
}
/*Returning count from doubly linked list*/
public int count(){
return count;
}
/*deleting specific node from doubly linked list*/
public void delete(String name){
Node current=head,previous=head;
/*if it is head node to be deleted*/
if(head.getData().equals(name)){
current=head.getNext();
current.setPrev(null);
head=current;
previous=head;
}else{
/*If node in middle of list*/
while(current.getNext()!=null){
if(current.getData().equals(name)){
current.getNext().setPrev(previous);
previous.setNext(current.getNext());
count--;
break;
}
previous=current;
current=current.getNext();
}
/*If node is at last*/
if(current.getNext()==null){
if(current.getData().equals(name)){
previous.setNext(null);
count--;
}
}
}
}
/*deleting all nodes from list by assigning head to null
* and memory releasing take care by garbage collector*/
public void clear(){
head=null;
count=0;
}
/*Inserting element in alphabetic order*/
public void insertAlpha(String name){
Node current=head,previous=head;
/*creating new node*/
Node newNode=new Node(name,null,null);
/*if head node is null*/
if(head==null){
head=newNode;
count++;
}else{
/*please read about compareTo() method about returning value*/
if(head.getData().compareTo(name)>0){
newNode.setNext(head);
head=newNode;
count++;
}else{
/*condition for getting position of node to be inserted*/
while(current!=null&¤t.getData().compareTo(name)<=0){
previous=current;
current=current.getNext();
}
/*if node need to be inserted at last*/
if(current==null){
previous=newNode;
}else{
/*If node need to inserted in middle*/
newNode.setNext(current);
previous.setNext(newNode);
current.setPrev(newNode);
newNode.setPrev(previous);
}
count++;
}
}
}
/*Main method start*/
public static void main(String args[]){
/*creating object of doubly linked list*/
DoublyLinkedList doublyLinkedList=new DoublyLinkedList();
doublyLinkedList.insertBeginning(\"sunita\");
doublyLinkedList.insertBeginning(\"lalchand\");
/*calling alphabetic order method*/
doublyLinkedList.insertAlpha(\"ramsingh\");
doublyLinkedList.insertBeginning(\"Lokesh\");
doublyLinkedList.insertBeginning(\"Pritam\");
/*****printing list********/
doublyLinkedList.printL.
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.
LabProgram.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition <>
* @return the value stored at node first
* @throws NoSuchElementException <>
*/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
/**
* Returns the value stored in the last node
* @precondition <>
* @return the value stored in the node last
* @throws NoSuchElementException <>
*/
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return iterator.data;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition <>
*/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition <>
*/
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIter.
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.
include ltinitializer_listgt include ltiostreamgt .pdficonsystemsslm
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <utility>
/************************************************************/
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
// TODO
// <->| 1 |<->| 2 |<->| 3 |<->| 4 |<->| 5 |<->| 6 |<->
// ^ ^
// begin end
//
// becomes
//
// <->| 1 |<->| 6 |<->
//
// begin and end do not need to change at all
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
// TODO
// this
// v
// <->| 1 |<->| 6 |<-> <->| 2 |<->| 3 |<->| 4 |<->
// ^ ^
// first last
//
// becomes
// this
// v
// <->| 1 |<->| 2 |<->| 3 |<->| 4 |<->| 6 |<->
// ^ ^
// first last
//
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};.
include ltinitializer_listgt include ltiostreamgt .pdfadisainternational
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <utility>
/************************************************************/
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
// TODO
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
// TODO
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};
Please complete the implementation of the missing part marked TODO.
// node insertion/removal [5] static Node:: unhook_range (Node* first, Node* last) [3] When first ==
last (single element) [2] When first != last [5] Node: :hook_range (Node* first, Node* last) [3] When
first != last [2] When first == last (single element).
include ltinitializer_listgt include ltiostreamgt .pdfabidtelecom
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <utility>
/************************************************************/
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
// TODO
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
// TODO
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};
Please complete the implementation of the missing part marked TODO..
tested on eclipseDoublyLinkedList class.pdfshanki7
//tested on eclipse
/*************DoublyLinkedList class*******************/
public class DoublyLinkedList {
/*Data member variable declaration*/
private Node head;
private int count;
/**default constructor*/
public DoublyLinkedList() {
/*Initializing variable*/
head=null;
count =0;
}
/*Insert at beginning in doubly linked list*/
public void insertBeginning(String name){
/*checking head is null then we will add node at head*/
if(head==null){
head=new Node(name, null, null);
count++;
}else{
/*else create temp node and setting next to head
* and then making temp to head*/
Node temp=new Node(name,null,null);
temp.setNext(head);
head.setPrev(temp);
head=temp;
count++;
}
}
public void printList(){
Node temp=head;
/*Printing element of doubly list*/
while(temp!=null){
System.out.println(temp.getData());
temp=temp.getNext();
}
}
/*Returning count from doubly linked list*/
public int count(){
return count;
}
/*deleting specific node from doubly linked list*/
public void delete(String name){
Node current=head,previous=head;
/*if it is head node to be deleted*/
if(head.getData().equals(name)){
current=head.getNext();
current.setPrev(null);
head=current;
previous=head;
}else{
/*If node in middle of list*/
while(current.getNext()!=null){
if(current.getData().equals(name)){
current.getNext().setPrev(previous);
previous.setNext(current.getNext());
count--;
break;
}
previous=current;
current=current.getNext();
}
/*If node is at last*/
if(current.getNext()==null){
if(current.getData().equals(name)){
previous.setNext(null);
count--;
}
}
}
}
/*deleting all nodes from list by assigning head to null
* and memory releasing take care by garbage collector*/
public void clear(){
head=null;
count=0;
}
/*Inserting element in alphabetic order*/
public void insertAlpha(String name){
Node current=head,previous=head;
/*creating new node*/
Node newNode=new Node(name,null,null);
/*if head node is null*/
if(head==null){
head=newNode;
count++;
}else{
/*please read about compareTo() method about returning value*/
if(head.getData().compareTo(name)>0){
newNode.setNext(head);
head=newNode;
count++;
}else{
/*condition for getting position of node to be inserted*/
while(current!=null&¤t.getData().compareTo(name)<=0){
previous=current;
current=current.getNext();
}
/*if node need to be inserted at last*/
if(current==null){
previous=newNode;
}else{
/*If node need to inserted in middle*/
newNode.setNext(current);
previous.setNext(newNode);
current.setPrev(newNode);
newNode.setPrev(previous);
}
count++;
}
}
}
/*Main method start*/
public static void main(String args[]){
/*creating object of doubly linked list*/
DoublyLinkedList doublyLinkedList=new DoublyLinkedList();
doublyLinkedList.insertBeginning(\"sunita\");
doublyLinkedList.insertBeginning(\"lalchand\");
/*calling alphabetic order method*/
doublyLinkedList.insertAlpha(\"ramsingh\");
doublyLinkedList.insertBeginning(\"Lokesh\");
doublyLinkedList.insertBeginning(\"Pritam\");
/*****printing list********/
doublyLinkedList.printL.
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.
LabProgram.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition <>
* @return the value stored at node first
* @throws NoSuchElementException <>
*/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
/**
* Returns the value stored in the last node
* @precondition <>
* @return the value stored in the node last
* @throws NoSuchElementException <>
*/
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return iterator.data;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition <>
*/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition <>
*/
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIter.
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.
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxwkyra78
Program 8 C++/newproblems.txt12333/14/2013KristinBrewer10328/23/2013MarciaStephenson12228/28/2013JeremySavage11519/4/2013AlfredReddy10919/20/2013JustinLiu11734/22/2013FrancisWheeler11114/25/2013JeremyChung11934/26/2013MonicaFuller11125/1/2013ClaraGraves10535/3/2013DorothyCox11135/8/2013BryanMcCall10215/13/2013LorraineTe107210/7/2013AndreaBraun110210/8/2013DebbieBritt124210/9/2013WandaEnnis118210/11/2013TammyGrant120310/15/2013DorothyFlowers116110/16/2013ChristineBullardrrell
Program 8 C++/orderLinkedList.h
//*********************************************
// The ListNode class creates a type used to *
// store a node of the linked list. *
// PRECONDITIONS: *
// Choice for ItemType implements 'cout' *
// as well as "==" and "<" operators *
//*********************************************
#ifndef OrderOrderLinkedList_H
#define OrderOrderLinkedList_H
template <class ItemType>
class ListNode
{
public:
ItemType info; // Node value
ListNode<ItemType> *next; // Pointer to the next node
// Constructor
ListNode (ItemType nodeValue)
{
info = nodeValue;
next = NULL;
}
};
//*********************************************
// OrderLinkedList class *
//*********************************************
template <class ItemType>
class OrderLinkedList
{
private:
ListNode<ItemType> *head; // List head pointer
ListNode<ItemType> *currentPos; // Pointer to "current" list item
int length; // Length
public:
OrderLinkedList(); // Constructor
~OrderLinkedList(); // Destructor
OrderLinkedList( const OrderLinkedList<ItemType>& anotherList ); // Copy constructor
void operator= ( const OrderLinkedList<ItemType>& ); // Assignment op
void insertNode(ItemType);
void deleteNode(ItemType);
bool searchList(ItemType& item);
int getLength();
void displayList();
void resetList();
ItemType getNextItem(); // Iterator
bool atEnd();
};
//**************************************************
// Constructor *
// Initial list head pointer and length *
//**************************************************
template <class ItemType>
OrderLinkedList<ItemType>::OrderLinkedList()
{
head = NULL;
length = 0;
}
//**************************************************
// displayList shows the value stored in each node *
// of the linked list pointed to by head. *
// Precondition: "cout" operator enabled for *
// ItemType data type. *
//**************************************************
template <class ItemType>
void OrderLinkedList<ItemType>::displayList()
{
List ...
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 have the following code and I need to know why I am receiving the .pdfezzi552
Edwards Manufacturing Company purchases two component parts from three different suppliers.
The suppliers have limited capacity, and no one supplier can meet all the company’s needs. In
addition, the suppliers charge different prices for the components. Component price data (in
price per unit) are as follows:
Each supplier has a limited capacity in terms of the total number of components it can supply.
However, as long as Edwards provides sufficient advance orders, each supplier can devote its
capacity to component 1, component 2, or any combination of the two components, if the total
number of units ordered is within its capacity. Supplier capacities are as follows:
If the Edwards production plan for the next period includes 1000 units of component 1 and 800
units of component 2, what purchases do you recommend? That is, how many units of each
component should be ordered from each supplier? Round your answers to the nearest whole
number.
What is the total purchase cost for the components? Round your answer to the nearest dollar.
$ ????SupplierComponent1231$11$10$132$10$11$11
Solution
For component 1:
supplier 2 have minimum cost and capacity 1050.
So all the component 1 (1000) can be purchased from supplier 2.
So, supplier 2 have 50 more capacity.
Now, supplier 1 have minimum cost for component 2 and have capacity of 650.
so, number of component 2 from supplier1 can be 650.
Now, we need 150 more component 2.
supplier 2 and 3 have same cost for component 2.
supllier have only 50 capacity now and supplier have 850.
So, 150 component 2 can be purchased from supplier 3.
Let y be the number of components fromSupplier123TotalcostComponent
1010000100010000Component 265001508008150Total cost18150.
In this lab, we will write an application to store a deck of cards i.pdfcontact41
In this lab, we will write an application to store a deck of cards in a linked list, and then write
methods to sort and shuffle the deck.
Copy your completed LinkedList class from Lab 4 into the LinkedList.java file below.
Complete all methods of the Card class as described by the Javadoc comments. The class
contains both a suit and a rank. A suit is one of the categories into which the cards of a deck are
divided. The rank is the relative importance of the card within its suit.
Note that the Card constructor must convert any rank and suit letters to uppercase.
For the equals() method, be sure to follow the steps outlined in Lesson 4. How to implement the
compareTo() method is also covered in Lesson 4.
Note that you are not allowed to add any additional methods or member variables to this class or
you will not receive credit for this assignment.
Complete all methods of the CardApp class in the CardApp.java file as described by the Javadoc
comments.
You may add as many methods as you would like to this file, but are not allowed to add any
additional member variables.
The CardApp program must prompt for and allow the user to enter the name of any input file as
shown in the Example output below.
Implement the shuffle() method as specified in the comments for shuffle(). After you have
shuffled the deck of cards, write the result into a file named shuffled.txt.
Implement the sort() method using bubble sort from Lesson 4. First sort by suit in alphabetical
order and then by rank from 2 to A. The pseudocode for bubble sort is as follows:
After you have sorted the deck of cards, write the result to a file named sorted.txt.
The CardApp.java file also contains the main() method of the application. Use Develop mode to
test your CardApp code along with your Card and LinkedList code.
All input and output files must contain a list of cards, with each card stored on its own line. See
the example files cards1.txt and cards2.txt for example file formats.
[[[cards1.txt]]]
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
[[[cards2.txt]]]
AS
2S
3S
4S
5S
6S
7S
8S
9S
10S
JS
QS
KS
AC
2C
3C
4C
5C
6C
7C
8C
9C
10C
JC
QC
KC
AH
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
QH
KH
AD
2D
3D
4D
5D
6D
7D
8D
9D
10D
JD
QD
KD
[[[CardApp.java]]]
/**
* CardApp.java
* @author Your name
* @author Partner's name
* CIS 22C, Applied Lab 1
*/
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public vo.
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.
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 do I fix it in LinkedList.javaLinkedList.java Define.pdfmail931892
How do I fix it in LinkedList.java?
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoSuchElementExcept.
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
Complete in Java
CardApp.java
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public void shuffle() {
}
/**
* Implements the bubble sort algorithm
* to sort cardList into sorted order, first by suit
* (alphabetical order)
* then by rank from 2 to A
*/
public void sort() {
}
/**
* Returns the deck of cards with each card separated
* by a blank space and a new line character at the end.
* @return The deck of cards as a string.
*/
@Override public String toString() {
return "";
}
}
Card.java
public class Card implements Comparable{
private String rank;
private String suit;
/**
* Constructor for the Card class
* @param rank the rank of card from 2 to A
* @param suit the suit of card C, D, H, or S
*/
public Card(String rank, String suit) {
}
/**
* Returns the card's rank
* @return rank a rank from 2 (low) to A (high)
*/
public String getRank() {
return "";
}
/**
* Returns the card's suit
* @return C, D, H, or S
*/
public String getSuit() {
return "";
}
/**
* Updates the card's rank
* @param rank a new rank
*/
public void setRank(String rank) {
}
/**
* Updates the card's suit
* @param suit the new suit
*/
public void setSuit(String suit) {
}
/**
* Concatenates rank and suit
* @return card rank and suit
*/
@Override public String toString() {
return "";
}
/**
* Overrides the equals method for Card
* Compares rank and suit and
* follows the equals formula given in
* Lesson 4 and also in Joshua Block's text
* @param obj another Object to compare for
* equality
* @return whether obj is a Card and, if so,
* of equal rank and suit
*/
@Override public boolean equals(Object obj) {
return false;
}
/**
* Orders two cards first by suit (alphabetically)
* Next by rank. "A" is considered the high card
* Order goes 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
* @param card another Card to compare to this Card
* @return a negative number if this comes before c
* and a positive number if c comes before this
* and 0 if this and c are equal according to the above
* equals method
*/
@Override public int compareTo(Card card) {
return -1;
}
}
}
LinkedList.Java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterato.
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
How do I fix it in java?
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoSuchElementException {
if(is.
Please read the comment ins codeExpressionTree.java-------------.pdfshanki7
Please read the comment ins code
ExpressionTree.java
----------------------------------
/**
* This is the class for Expression Tree.
* Used to create Expression Tree and Evaluate it
*/
/**
* Following logic is used to construct a Tree
* Here we use stack for Preparing Tree
* Loop through given Expression String
* If Character is Operand , Create node and push to stack
* If Character is Operator then
* 1)Create Node for Operator
* 2)Pop 2 nodes from Stack and Made
* OpretorNode--> left == first node pop
* OpretorNode--> right == second node pop
* At the end of creation of Expression Tree, Stack have only one node , which is root of
Expression tree
*/
/** Class ExpressionTree **/
class ExpressionTree
{
/** class TreeNode
* Stored Character ==> Digit(0..9) or a Operator +,-,*,/
* Left Node and Right Node
*
* **/
class TreeNode
{
char data;
TreeNode left, right;
/** constructor **/
public TreeNode(char data)
{
this.data = data;
this.left = null;
this.right = null;
}
}
/** class StackNode **/
class StackNode
{
TreeNode treeNode;
StackNode next;
/** constructor **/
public StackNode(TreeNode treeNode)
{
this.treeNode = treeNode;
next = null;
}
}
private static StackNode top;
/** constructor
* Constructor takes input string like \"+-+7*935*82*625\"
* Input should be in Prefix notation
* **/
public ExpressionTree(String expression)
{
top = null;
//Call Method for prepare expression tree
buildTree(expression);
}
/** function to clear tree **/
public void clear()
{
top = null;
}
/** function to push a node **/
private void push(TreeNode ptr)
{
if (top == null)
top = new StackNode(ptr);
else
{
StackNode nptr = new StackNode(ptr);
nptr.next = top;
top = nptr;
}
}
/** function to pop a node
* When it find operator pop 2 elements from Stack
*
* **/
private TreeNode pop()
{
if (top == null)
throw new RuntimeException(\"Underflow\");
else
{
TreeNode ptr = top.treeNode;
top = top.next;
return ptr;
}
}
/** function to get top node **/
private TreeNode peek()
{
return top.treeNode;
}
/** function to insert character **/
private void insert(char val)
{
try
{
//If Operand , Create node and push to Stack
if (isDigit(val))
{
TreeNode nptr = new TreeNode(val);
push(nptr);
}
//If Operator , Create node and popup 2 elements and make them its right and left
else if (isOperator(val))
{
TreeNode nptr = new TreeNode(val);
nptr.left = pop();
nptr.right = pop();
push(nptr);
}
}
catch (Exception e)
{
System.out.println(\"Invalid Expression\");
}
}
/** function to check if digit **/
private boolean isDigit(char ch)
{
return ch >= \'0\' && ch <= \'9\';
}
/** function to check if operator **/
private boolean isOperator(char ch)
{
return ch == \'+\' || ch == \'-\' || ch == \'*\' || ch == \'/\';
}
/** function to convert character to digit **/
private int toDigit(char ch)
{
return ch - \'0\';
}
/** function to build tree from input */
public void buildTree(String eqn)
{
for (int i = eqn.length() - 1; i >= 0; i--)
insert(eqn.charAt(i));
}
/** function to evaluate tree */
public dou.
Getting the following errorsError 1 error C2436 {ctor} mem.pdfherminaherman
Getting the following errors:
Error 1 error C2436: \'{ctor}\' : member function or nested class in constructor initializer list on
line 565
Error 2 error C2436: \'{ctor}\' : member function or nested class in constructor initializer list on
line 761
I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!!
#include
#include
#include
#include
using namespace std;
enum contactGroupType
{// used in extPersonType
FAMILY,
FRIEND,
BUSINESS,
UNFILLED
};
class addressType
{
private:
string st_address;
string city;
string state;
int zip;
public:
void print(string, string, string, int)const;
void setStreet(string);
string getStreet()const;
void setCity(string);
string getCity()const;
void setState(string);
string getState()const;
void setZip(int);
int getZip()const;
void set(string, string, string, int);// set all address fields
string get()const;// get address as one concatenated string
addressType();
// ~addressType();
};
class personType
{
private:
string firstName;
string lastName;
public:
void print()const;
void setName(string first, string last);
string getFirstName()const;
string getLastName()const;
string get()const;// return First Last names concatenated
personType & operator=(const personType &);
personType(string, string);
personType();
};
class dateType
{
private:
int dMonth;
int dDay;
int dYear;
public:
void setDate(int month, int day, int year);
int getDay()const;
int getMonth()const;
int getYear()const;
void print()const;
string get()const;// return string representation as DD/MM/YYYY
dateType & operator=(const dateType & d);
dateType(int, int, int);
dateType();
};
class extPersonType :public personType {
private:
addressType address;// added members
dateType birthday;
contactGroupType group;
string phone;
public:
// methods
void setPhone(string);
string getPhone()const;
void setGroup(contactGroupType);
contactGroupType getGroup()const;
void setBirthday(int, int, int);
dateType getBirthday()const;
void print();
string get()const;// return string representation of ext person type
extPersonType & operator=(const extPersonType & p);
string groupToString(contactGroupType)const;
contactGroupType stringToGroup(string)const;
// constructors
extPersonType();
extPersonType(string first, string last);
};
// because we have no arrayListType, we are using our own
// implementation with a small subset of functions
class arrayListType
{
extPersonType array[500];
int size;
public:
arrayListType();
extPersonType & operator[](int i);
void removeLast();// remove last element
void add(const extPersonType &);// add new element
int getSize()const;// get array size
};
class addressBookType :public arrayListType
{
private:
static const char FS = \'\\t\';// field separator in file (TAB char)
int current;// current position
string fileName;// filename
fstream fileStream;// file as fstream
/* filiters */
contactGroupType fltGroup;
string fltFromLast, fltToLast;
dateType fltFromDate, fltTiDate;
/* flags for effective filters */
bool fl.
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfsupport58
Please complete ALL of the TO DOs in this code. I am really struggling with this assignment.
The last time I posted this question, they did not complete them all. Please do it! There are two
files, list.h and queue.h. I tried to complete this on my own and none of it worked, so I am
posting the template again instead of my nonworking code. Please do not use chatgpt, I think the
last person used it.
list.h:
#pragma once
#include // size_t
#include // std::bidirectional_iterator_tag
#include // std::is_same, std::enable_if
template
class List {
private:
struct Node {
Node *next, *prev;
T data;
explicit Node(Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev} {}
explicit Node(const T& data, Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev}, data{data} {}
explicit Node(T&& data, Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev}, data{std::move(data)} {}
};
template
class basic_iterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = T;
using difference_type = ptrdiff_t;
using pointer = pointer_type;
using reference = reference_type;
private:
friend class List;
using Node = typename List::Node;
Node* node;
explicit basic_iterator(Node* ptr) noexcept : node{ptr} {}
explicit basic_iterator(const Node* ptr) noexcept : node{const_cast(ptr)} {}
public:
basic_iterator() { /* TODO */ };
basic_iterator(const basic_iterator&) = default;
basic_iterator(basic_iterator&&) = default;
~basic_iterator() = default;
basic_iterator& operator=(const basic_iterator&) = default;
basic_iterator& operator=(basic_iterator&&) = default;
reference operator*() const {
// TODO
}
pointer operator->() const {
// TODO
}
// Prefix Increment: ++a
basic_iterator& operator++() {
// TODO
}
// Postfix Increment: a++
basic_iterator operator++(int) {
// TODO
}
// Prefix Decrement: --a
basic_iterator& operator--() {
// TODO
}
// Postfix Decrement: a--
basic_iterator operator--(int) {
// TODO
}
bool operator==(const basic_iterator& other) const noexcept {
// TODO
}
bool operator!=(const basic_iterator& other) const noexcept {
// TODO
}
};
public:
using value_type = T;
using size_type = size_t;
using difference_type = ptrdiff_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = value_type*;
using const_pointer = const value_type*;
using iterator = basic_iterator;
using const_iterator = basic_iterator;
private:
Node head, tail;
size_type _size;
public:
List() {
// TODO - Don't forget to initialize the list beforehand
}
List( size_type count, const T& value ) {
// TODO - Don't forget initialize the list beforehand
}
explicit List( size_type count ) {
// TODO - Don't forget initialize the list beforehand
}
List( const List& other ) {
// TODO - Don't forget initialize the list beforehand
}
List( List&& other ) {
// TODO - Don't forget initialize the list beforehand
}
~List() {
// TODO
}
List& operator=( const List& other ) {
// TODO
}
List& operator=( List&& o.
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.
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
.
I need help completing this C++ code with these requirements.instr.pdfeyeonsecuritysystems
I need help completing this C++ code with these requirements.
instructions: IN C++ LANGUAGE PLEASE
Update the comments for each prototype by filling in the pre and post conditions.
Remember that pre conditions indicate what conditions must be met BEFORE the user calls the
function. The function will not work properly unless the pre conditions are met.
Post conditions indicate what will be the result of the function call. In other words, what
conditions will exist after the function is called.
See class notes from Thursday on pre and post conditions for some examples and further
explanation.
Code begins here:
#include //for NULL
class List
{
private:
struct Node
{
int data;
Node* next;
Node(int data): data(data), next(NULL){}
};
typedef struct Node* Nodeptr;
Nodeptr first;
Nodeptr last;
int size;
public:
/**Constructors and Destructors*/
List();
//Default constructor; initializes and empty list
//Postcondition:
~List();
//Destructor. Frees memory allocated to the list
//Postcondition:
/**Accessors*/
int getFirst();
//Returns the first element in the list
//Precondition:
int getLast();
//Returns the last element in the list
//Precondition:
bool isEmpty();
//Determines whether a list is empty.
int getSize();
//Returns the size of the list
/**Manipulation Procedures*/
void removeLast();
//Removes the value of the last element in the list
//Precondition:
//Postcondition:
void removeFirst();
//Removes the value of the first element in the list
//Precondition:
//Postcondition:
void insertLast(int data);
//Inserts a new element at the end of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
void insertFirst(int data);
//Inserts a new element at the start of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
/**Additional List Operations*/
void printList();
//Prints to the console the value of each element in the list sequentially
//and separated by a blank space
//Prints nothing if the list is empty
};
Solution
PROGRAM CODE:
#include
#include //for NULL
using namespace std;
class List
{
private:
struct Node
{
int data;
Node* next;
Node(int data): data(data), next(NULL){}
};
typedef struct Node* Nodeptr;
Nodeptr first;
Nodeptr last;
int size;
public:
/**Constructors and Destructors*/
List()
{
first = (Node*) malloc(sizeof(Node));
last = (Node*) malloc(sizeof(Node));
size = 0;
}
//Default constructor; initializes and empty list
//Postcondition:
~List()
{
delete first;
delete last;
}
//Destructor. Frees memory allocated to the list
//Postcondition:
/**Accessors*/
int getFirst()
{
return first->data;
}
//Returns the first element in the list
//Precondition:
int getLast()
{
return last->data;
}
//Returns the last element in the list
//Precondition:
bool isEmpty()
{
if(first == NULL)
return true;
else return false;
}
//Determines whether a list is empty.
int getSize()
{
return size;
}
//Returns the size of the list
/**Manipulation Procedures*/
void removeLast()
{
last = .
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
Need Help!! C++
#include<iostream>
#include"linkedlist.h"
using namespace std;
/**
* @brief Destructor to destroy all nodes and release memory
*/
LinkedList::~LinkedList() {
//TODO: Add code here. Make sure memory is released properly.
}
/**
* @brief Purpose: Checks if the list is empty
* @return true if the list is empty, false otherwise
*/
bool LinkedList::isEmpty() const {
// TODO: Add code here
return count == 0;
}
/**
* @brief Get the number of nodes in the list
* @return int The number of nodes in the list
*/
int LinkedList::length() const{
//TODO: Add code here
}
/**
* @brief Convert the list to a string
*
*/
string LinkedList::toString() {
string str = "[";
Node *ptr = front;
if (ptr != nullptr) {
// Head node is not preceded by separator
str += to_string(ptr->val);
ptr = ptr->next;
}
while (ptr != nullptr) {
str += ", " + to_string(ptr->val);
ptr = ptr->next;
}
str += "]";
return str;
}
/**
* @brief Displays the contents of the list
*/
void LinkedList::displayAll() {
cout << toString() << endl;
}
//TODO: Add comments
void LinkedList::addRear(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
void LinkedList::addFront(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
bool LinkedList::deleteFront(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
//TODO: Add comments
bool LinkedList::deleteRear(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
/* --- harder ones for test 2 and 3 -- */
/**
* @brief Delete a node at a given position from the list. The
* node at position pos is deleted and the value of the deleted node is returned in val.
* The valid range of pos is 1 to count. pos = 1 is the first node, and pos = count is the last node.
* @param pos: position of the node to be deleted
* @param val: it is set to the value of the node to be deleted
* @return true: if the node was deleted successfully
* @return false: if the node was not deleted successfully because the position was out of range
*/
bool LinkedList::deleteAt(int pos, T &val) {
//TODO: Add code here
// check if the pos is valid first, then move the ptr to the rigth positon
// consider the special case of deleting the first node and the last node
// Do not forget to set value.
}
/**
* @brief Insert a value at a specified position in the list. The valid pos is in the range of 1 to
count+1.
* The value will be inserted before the node at the specified position. if pos = 1, the value will be
inserted
* at the front of the list. if pos = count+1, the value will be inserted at the rear of the list.
* @param pos: position to insert the value at.
* @param val: value to insert.
* @return true: if the value was inserte.
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
Merge Sort implementation in C++ The implementation for Mergesort given in Section 7.4 takes
an array as input and soils that array. At the beginning of Section 7.4 there is a simple
pseudocode implementation for sorting a linked list using Mergesort. Implement both a linked
list-based version of Mergesort and the array-based version of Mergesort. and compare and
analyze their running times.
Solution
/* Merger sort array-based version */
/* C program for Merge Sort */
#include
#include
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
/* UTILITY FUNCTIONS */
/* Function to print an array */
void printArray(int A[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", A[i]);
printf(\"\ \");
}
/* Driver program to test above functions */
int main()
{
int arr[] = {12, 11, 13, 5, 6, 7};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf(\"Given array is \ \");
printArray(arr, arr_size);
mergeSort(arr, 0, arr_size - 1);
printf(\"\ Sorted array is \ \");
printArray(arr, arr_size);
return 0;
}
--------------------------------------------------------------------------------------------------------------------
/* merge sort link-list version
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function prototypes */
struct node* SortedMerge(struct node* a, struct node* b);
void FrontBackSplit(struct node* source,
struct node** frontRef, struct node** backRef);
/* sorts the linked list by changing next pointers (not data) */
void MergeSort(struct node** headRef)
{
struct node* head = *headRef;
struct node* a;
struct node* b;
/* Base case -- length 0 or 1 */
if ((head == NULL) || (head->next == NULL))
{
return;
}
/* Split head into \'a\' and \'b\' sublists */
FrontBackSplit(head, &a, &b);
/* Recursively sort the sublists */
MergeSort(&a);
MergeSort(&b);
/* answer = merge the two sorted lists together */
*.
0 Suppose that a subsidy plan is introduced for lowincome .pdfajay1317
- Rely as little as possible on automatic stabilizers 19. The paradox of thrift is an example of: - Too
much saving relative to exports - A fallacy of composition - Automatic stabilizers - Fractional
reserve banking 20. If the US dollar purchases more Mexican pesos: - The dollar has depreciated
- The peso has appreciated - Both the dollar and the peso have appreciated - The peso has
depreciated 21. True/False: It is possible for a country to invest more than it saves while running a
balanced fiscal budget and a trade surplus. - True - False.
+ 1D 1W1M3M1Y5Y Your position Shares Market value 15 145.pdfajay1317
- Part (a) State the null hypothesis. H0:m=e H0:me H0:m<e H0:me Part (b) Part (c) Part (d) State
the distribution to use for the test. (Enter your answer in the form z or tdf where df is the degrees
of freedom. Round your answer to two decimal places.) x Part (e) What is the test statistic? (If
using the z distribution round your answer to two decimal places, and if using the t distribution
round your answer to three decimal places.) -- Select-- V= Part(f) What is the p-value? (Round
your answer to four decimal places.) Explain what the p-value means for this problem. If H0 is
false, then there is a chance equal to the -value that the sample mean salary of mechanical
engineers is $300 more than the sample mean salary of electrical engineers. If H0 is true, then
there is a chance equal to the p-value that the sample mean salary of mechanical engineers is
$300 more than the sample mean salary of electrical engineers. If H0 is true, then there is a
chance equal to the p-value that the sample mean salary of mechanical engineers is at least $300
less than the sample mean salary of electrical engineers. If H0 is false, then there is a chance
equal to the p-value that the sample mean salary of mechanical engineers is at least $300 less
than the sample mean salary of electrical engineers..
More Related Content
Similar to for initializer_list include ltinitializer_listgt .pdf
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxwkyra78
Program 8 C++/newproblems.txt12333/14/2013KristinBrewer10328/23/2013MarciaStephenson12228/28/2013JeremySavage11519/4/2013AlfredReddy10919/20/2013JustinLiu11734/22/2013FrancisWheeler11114/25/2013JeremyChung11934/26/2013MonicaFuller11125/1/2013ClaraGraves10535/3/2013DorothyCox11135/8/2013BryanMcCall10215/13/2013LorraineTe107210/7/2013AndreaBraun110210/8/2013DebbieBritt124210/9/2013WandaEnnis118210/11/2013TammyGrant120310/15/2013DorothyFlowers116110/16/2013ChristineBullardrrell
Program 8 C++/orderLinkedList.h
//*********************************************
// The ListNode class creates a type used to *
// store a node of the linked list. *
// PRECONDITIONS: *
// Choice for ItemType implements 'cout' *
// as well as "==" and "<" operators *
//*********************************************
#ifndef OrderOrderLinkedList_H
#define OrderOrderLinkedList_H
template <class ItemType>
class ListNode
{
public:
ItemType info; // Node value
ListNode<ItemType> *next; // Pointer to the next node
// Constructor
ListNode (ItemType nodeValue)
{
info = nodeValue;
next = NULL;
}
};
//*********************************************
// OrderLinkedList class *
//*********************************************
template <class ItemType>
class OrderLinkedList
{
private:
ListNode<ItemType> *head; // List head pointer
ListNode<ItemType> *currentPos; // Pointer to "current" list item
int length; // Length
public:
OrderLinkedList(); // Constructor
~OrderLinkedList(); // Destructor
OrderLinkedList( const OrderLinkedList<ItemType>& anotherList ); // Copy constructor
void operator= ( const OrderLinkedList<ItemType>& ); // Assignment op
void insertNode(ItemType);
void deleteNode(ItemType);
bool searchList(ItemType& item);
int getLength();
void displayList();
void resetList();
ItemType getNextItem(); // Iterator
bool atEnd();
};
//**************************************************
// Constructor *
// Initial list head pointer and length *
//**************************************************
template <class ItemType>
OrderLinkedList<ItemType>::OrderLinkedList()
{
head = NULL;
length = 0;
}
//**************************************************
// displayList shows the value stored in each node *
// of the linked list pointed to by head. *
// Precondition: "cout" operator enabled for *
// ItemType data type. *
//**************************************************
template <class ItemType>
void OrderLinkedList<ItemType>::displayList()
{
List ...
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 have the following code and I need to know why I am receiving the .pdfezzi552
Edwards Manufacturing Company purchases two component parts from three different suppliers.
The suppliers have limited capacity, and no one supplier can meet all the company’s needs. In
addition, the suppliers charge different prices for the components. Component price data (in
price per unit) are as follows:
Each supplier has a limited capacity in terms of the total number of components it can supply.
However, as long as Edwards provides sufficient advance orders, each supplier can devote its
capacity to component 1, component 2, or any combination of the two components, if the total
number of units ordered is within its capacity. Supplier capacities are as follows:
If the Edwards production plan for the next period includes 1000 units of component 1 and 800
units of component 2, what purchases do you recommend? That is, how many units of each
component should be ordered from each supplier? Round your answers to the nearest whole
number.
What is the total purchase cost for the components? Round your answer to the nearest dollar.
$ ????SupplierComponent1231$11$10$132$10$11$11
Solution
For component 1:
supplier 2 have minimum cost and capacity 1050.
So all the component 1 (1000) can be purchased from supplier 2.
So, supplier 2 have 50 more capacity.
Now, supplier 1 have minimum cost for component 2 and have capacity of 650.
so, number of component 2 from supplier1 can be 650.
Now, we need 150 more component 2.
supplier 2 and 3 have same cost for component 2.
supllier have only 50 capacity now and supplier have 850.
So, 150 component 2 can be purchased from supplier 3.
Let y be the number of components fromSupplier123TotalcostComponent
1010000100010000Component 265001508008150Total cost18150.
In this lab, we will write an application to store a deck of cards i.pdfcontact41
In this lab, we will write an application to store a deck of cards in a linked list, and then write
methods to sort and shuffle the deck.
Copy your completed LinkedList class from Lab 4 into the LinkedList.java file below.
Complete all methods of the Card class as described by the Javadoc comments. The class
contains both a suit and a rank. A suit is one of the categories into which the cards of a deck are
divided. The rank is the relative importance of the card within its suit.
Note that the Card constructor must convert any rank and suit letters to uppercase.
For the equals() method, be sure to follow the steps outlined in Lesson 4. How to implement the
compareTo() method is also covered in Lesson 4.
Note that you are not allowed to add any additional methods or member variables to this class or
you will not receive credit for this assignment.
Complete all methods of the CardApp class in the CardApp.java file as described by the Javadoc
comments.
You may add as many methods as you would like to this file, but are not allowed to add any
additional member variables.
The CardApp program must prompt for and allow the user to enter the name of any input file as
shown in the Example output below.
Implement the shuffle() method as specified in the comments for shuffle(). After you have
shuffled the deck of cards, write the result into a file named shuffled.txt.
Implement the sort() method using bubble sort from Lesson 4. First sort by suit in alphabetical
order and then by rank from 2 to A. The pseudocode for bubble sort is as follows:
After you have sorted the deck of cards, write the result to a file named sorted.txt.
The CardApp.java file also contains the main() method of the application. Use Develop mode to
test your CardApp code along with your Card and LinkedList code.
All input and output files must contain a list of cards, with each card stored on its own line. See
the example files cards1.txt and cards2.txt for example file formats.
[[[cards1.txt]]]
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
[[[cards2.txt]]]
AS
2S
3S
4S
5S
6S
7S
8S
9S
10S
JS
QS
KS
AC
2C
3C
4C
5C
6C
7C
8C
9C
10C
JC
QC
KC
AH
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
QH
KH
AD
2D
3D
4D
5D
6D
7D
8D
9D
10D
JD
QD
KD
[[[CardApp.java]]]
/**
* CardApp.java
* @author Your name
* @author Partner's name
* CIS 22C, Applied Lab 1
*/
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public vo.
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.
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 do I fix it in LinkedList.javaLinkedList.java Define.pdfmail931892
How do I fix it in LinkedList.java?
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoSuchElementExcept.
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
Complete in Java
CardApp.java
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public void shuffle() {
}
/**
* Implements the bubble sort algorithm
* to sort cardList into sorted order, first by suit
* (alphabetical order)
* then by rank from 2 to A
*/
public void sort() {
}
/**
* Returns the deck of cards with each card separated
* by a blank space and a new line character at the end.
* @return The deck of cards as a string.
*/
@Override public String toString() {
return "";
}
}
Card.java
public class Card implements Comparable{
private String rank;
private String suit;
/**
* Constructor for the Card class
* @param rank the rank of card from 2 to A
* @param suit the suit of card C, D, H, or S
*/
public Card(String rank, String suit) {
}
/**
* Returns the card's rank
* @return rank a rank from 2 (low) to A (high)
*/
public String getRank() {
return "";
}
/**
* Returns the card's suit
* @return C, D, H, or S
*/
public String getSuit() {
return "";
}
/**
* Updates the card's rank
* @param rank a new rank
*/
public void setRank(String rank) {
}
/**
* Updates the card's suit
* @param suit the new suit
*/
public void setSuit(String suit) {
}
/**
* Concatenates rank and suit
* @return card rank and suit
*/
@Override public String toString() {
return "";
}
/**
* Overrides the equals method for Card
* Compares rank and suit and
* follows the equals formula given in
* Lesson 4 and also in Joshua Block's text
* @param obj another Object to compare for
* equality
* @return whether obj is a Card and, if so,
* of equal rank and suit
*/
@Override public boolean equals(Object obj) {
return false;
}
/**
* Orders two cards first by suit (alphabetically)
* Next by rank. "A" is considered the high card
* Order goes 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
* @param card another Card to compare to this Card
* @return a negative number if this comes before c
* and a positive number if c comes before this
* and 0 if this and c are equal according to the above
* equals method
*/
@Override public int compareTo(Card card) {
return -1;
}
}
}
LinkedList.Java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterato.
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
How do I fix it in java?
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoSuchElementException {
if(is.
Please read the comment ins codeExpressionTree.java-------------.pdfshanki7
Please read the comment ins code
ExpressionTree.java
----------------------------------
/**
* This is the class for Expression Tree.
* Used to create Expression Tree and Evaluate it
*/
/**
* Following logic is used to construct a Tree
* Here we use stack for Preparing Tree
* Loop through given Expression String
* If Character is Operand , Create node and push to stack
* If Character is Operator then
* 1)Create Node for Operator
* 2)Pop 2 nodes from Stack and Made
* OpretorNode--> left == first node pop
* OpretorNode--> right == second node pop
* At the end of creation of Expression Tree, Stack have only one node , which is root of
Expression tree
*/
/** Class ExpressionTree **/
class ExpressionTree
{
/** class TreeNode
* Stored Character ==> Digit(0..9) or a Operator +,-,*,/
* Left Node and Right Node
*
* **/
class TreeNode
{
char data;
TreeNode left, right;
/** constructor **/
public TreeNode(char data)
{
this.data = data;
this.left = null;
this.right = null;
}
}
/** class StackNode **/
class StackNode
{
TreeNode treeNode;
StackNode next;
/** constructor **/
public StackNode(TreeNode treeNode)
{
this.treeNode = treeNode;
next = null;
}
}
private static StackNode top;
/** constructor
* Constructor takes input string like \"+-+7*935*82*625\"
* Input should be in Prefix notation
* **/
public ExpressionTree(String expression)
{
top = null;
//Call Method for prepare expression tree
buildTree(expression);
}
/** function to clear tree **/
public void clear()
{
top = null;
}
/** function to push a node **/
private void push(TreeNode ptr)
{
if (top == null)
top = new StackNode(ptr);
else
{
StackNode nptr = new StackNode(ptr);
nptr.next = top;
top = nptr;
}
}
/** function to pop a node
* When it find operator pop 2 elements from Stack
*
* **/
private TreeNode pop()
{
if (top == null)
throw new RuntimeException(\"Underflow\");
else
{
TreeNode ptr = top.treeNode;
top = top.next;
return ptr;
}
}
/** function to get top node **/
private TreeNode peek()
{
return top.treeNode;
}
/** function to insert character **/
private void insert(char val)
{
try
{
//If Operand , Create node and push to Stack
if (isDigit(val))
{
TreeNode nptr = new TreeNode(val);
push(nptr);
}
//If Operator , Create node and popup 2 elements and make them its right and left
else if (isOperator(val))
{
TreeNode nptr = new TreeNode(val);
nptr.left = pop();
nptr.right = pop();
push(nptr);
}
}
catch (Exception e)
{
System.out.println(\"Invalid Expression\");
}
}
/** function to check if digit **/
private boolean isDigit(char ch)
{
return ch >= \'0\' && ch <= \'9\';
}
/** function to check if operator **/
private boolean isOperator(char ch)
{
return ch == \'+\' || ch == \'-\' || ch == \'*\' || ch == \'/\';
}
/** function to convert character to digit **/
private int toDigit(char ch)
{
return ch - \'0\';
}
/** function to build tree from input */
public void buildTree(String eqn)
{
for (int i = eqn.length() - 1; i >= 0; i--)
insert(eqn.charAt(i));
}
/** function to evaluate tree */
public dou.
Getting the following errorsError 1 error C2436 {ctor} mem.pdfherminaherman
Getting the following errors:
Error 1 error C2436: \'{ctor}\' : member function or nested class in constructor initializer list on
line 565
Error 2 error C2436: \'{ctor}\' : member function or nested class in constructor initializer list on
line 761
I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!!
#include
#include
#include
#include
using namespace std;
enum contactGroupType
{// used in extPersonType
FAMILY,
FRIEND,
BUSINESS,
UNFILLED
};
class addressType
{
private:
string st_address;
string city;
string state;
int zip;
public:
void print(string, string, string, int)const;
void setStreet(string);
string getStreet()const;
void setCity(string);
string getCity()const;
void setState(string);
string getState()const;
void setZip(int);
int getZip()const;
void set(string, string, string, int);// set all address fields
string get()const;// get address as one concatenated string
addressType();
// ~addressType();
};
class personType
{
private:
string firstName;
string lastName;
public:
void print()const;
void setName(string first, string last);
string getFirstName()const;
string getLastName()const;
string get()const;// return First Last names concatenated
personType & operator=(const personType &);
personType(string, string);
personType();
};
class dateType
{
private:
int dMonth;
int dDay;
int dYear;
public:
void setDate(int month, int day, int year);
int getDay()const;
int getMonth()const;
int getYear()const;
void print()const;
string get()const;// return string representation as DD/MM/YYYY
dateType & operator=(const dateType & d);
dateType(int, int, int);
dateType();
};
class extPersonType :public personType {
private:
addressType address;// added members
dateType birthday;
contactGroupType group;
string phone;
public:
// methods
void setPhone(string);
string getPhone()const;
void setGroup(contactGroupType);
contactGroupType getGroup()const;
void setBirthday(int, int, int);
dateType getBirthday()const;
void print();
string get()const;// return string representation of ext person type
extPersonType & operator=(const extPersonType & p);
string groupToString(contactGroupType)const;
contactGroupType stringToGroup(string)const;
// constructors
extPersonType();
extPersonType(string first, string last);
};
// because we have no arrayListType, we are using our own
// implementation with a small subset of functions
class arrayListType
{
extPersonType array[500];
int size;
public:
arrayListType();
extPersonType & operator[](int i);
void removeLast();// remove last element
void add(const extPersonType &);// add new element
int getSize()const;// get array size
};
class addressBookType :public arrayListType
{
private:
static const char FS = \'\\t\';// field separator in file (TAB char)
int current;// current position
string fileName;// filename
fstream fileStream;// file as fstream
/* filiters */
contactGroupType fltGroup;
string fltFromLast, fltToLast;
dateType fltFromDate, fltTiDate;
/* flags for effective filters */
bool fl.
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfsupport58
Please complete ALL of the TO DOs in this code. I am really struggling with this assignment.
The last time I posted this question, they did not complete them all. Please do it! There are two
files, list.h and queue.h. I tried to complete this on my own and none of it worked, so I am
posting the template again instead of my nonworking code. Please do not use chatgpt, I think the
last person used it.
list.h:
#pragma once
#include // size_t
#include // std::bidirectional_iterator_tag
#include // std::is_same, std::enable_if
template
class List {
private:
struct Node {
Node *next, *prev;
T data;
explicit Node(Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev} {}
explicit Node(const T& data, Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev}, data{data} {}
explicit Node(T&& data, Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev}, data{std::move(data)} {}
};
template
class basic_iterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = T;
using difference_type = ptrdiff_t;
using pointer = pointer_type;
using reference = reference_type;
private:
friend class List;
using Node = typename List::Node;
Node* node;
explicit basic_iterator(Node* ptr) noexcept : node{ptr} {}
explicit basic_iterator(const Node* ptr) noexcept : node{const_cast(ptr)} {}
public:
basic_iterator() { /* TODO */ };
basic_iterator(const basic_iterator&) = default;
basic_iterator(basic_iterator&&) = default;
~basic_iterator() = default;
basic_iterator& operator=(const basic_iterator&) = default;
basic_iterator& operator=(basic_iterator&&) = default;
reference operator*() const {
// TODO
}
pointer operator->() const {
// TODO
}
// Prefix Increment: ++a
basic_iterator& operator++() {
// TODO
}
// Postfix Increment: a++
basic_iterator operator++(int) {
// TODO
}
// Prefix Decrement: --a
basic_iterator& operator--() {
// TODO
}
// Postfix Decrement: a--
basic_iterator operator--(int) {
// TODO
}
bool operator==(const basic_iterator& other) const noexcept {
// TODO
}
bool operator!=(const basic_iterator& other) const noexcept {
// TODO
}
};
public:
using value_type = T;
using size_type = size_t;
using difference_type = ptrdiff_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = value_type*;
using const_pointer = const value_type*;
using iterator = basic_iterator;
using const_iterator = basic_iterator;
private:
Node head, tail;
size_type _size;
public:
List() {
// TODO - Don't forget to initialize the list beforehand
}
List( size_type count, const T& value ) {
// TODO - Don't forget initialize the list beforehand
}
explicit List( size_type count ) {
// TODO - Don't forget initialize the list beforehand
}
List( const List& other ) {
// TODO - Don't forget initialize the list beforehand
}
List( List&& other ) {
// TODO - Don't forget initialize the list beforehand
}
~List() {
// TODO
}
List& operator=( const List& other ) {
// TODO
}
List& operator=( List&& o.
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.
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
.
I need help completing this C++ code with these requirements.instr.pdfeyeonsecuritysystems
I need help completing this C++ code with these requirements.
instructions: IN C++ LANGUAGE PLEASE
Update the comments for each prototype by filling in the pre and post conditions.
Remember that pre conditions indicate what conditions must be met BEFORE the user calls the
function. The function will not work properly unless the pre conditions are met.
Post conditions indicate what will be the result of the function call. In other words, what
conditions will exist after the function is called.
See class notes from Thursday on pre and post conditions for some examples and further
explanation.
Code begins here:
#include //for NULL
class List
{
private:
struct Node
{
int data;
Node* next;
Node(int data): data(data), next(NULL){}
};
typedef struct Node* Nodeptr;
Nodeptr first;
Nodeptr last;
int size;
public:
/**Constructors and Destructors*/
List();
//Default constructor; initializes and empty list
//Postcondition:
~List();
//Destructor. Frees memory allocated to the list
//Postcondition:
/**Accessors*/
int getFirst();
//Returns the first element in the list
//Precondition:
int getLast();
//Returns the last element in the list
//Precondition:
bool isEmpty();
//Determines whether a list is empty.
int getSize();
//Returns the size of the list
/**Manipulation Procedures*/
void removeLast();
//Removes the value of the last element in the list
//Precondition:
//Postcondition:
void removeFirst();
//Removes the value of the first element in the list
//Precondition:
//Postcondition:
void insertLast(int data);
//Inserts a new element at the end of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
void insertFirst(int data);
//Inserts a new element at the start of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
/**Additional List Operations*/
void printList();
//Prints to the console the value of each element in the list sequentially
//and separated by a blank space
//Prints nothing if the list is empty
};
Solution
PROGRAM CODE:
#include
#include //for NULL
using namespace std;
class List
{
private:
struct Node
{
int data;
Node* next;
Node(int data): data(data), next(NULL){}
};
typedef struct Node* Nodeptr;
Nodeptr first;
Nodeptr last;
int size;
public:
/**Constructors and Destructors*/
List()
{
first = (Node*) malloc(sizeof(Node));
last = (Node*) malloc(sizeof(Node));
size = 0;
}
//Default constructor; initializes and empty list
//Postcondition:
~List()
{
delete first;
delete last;
}
//Destructor. Frees memory allocated to the list
//Postcondition:
/**Accessors*/
int getFirst()
{
return first->data;
}
//Returns the first element in the list
//Precondition:
int getLast()
{
return last->data;
}
//Returns the last element in the list
//Precondition:
bool isEmpty()
{
if(first == NULL)
return true;
else return false;
}
//Determines whether a list is empty.
int getSize()
{
return size;
}
//Returns the size of the list
/**Manipulation Procedures*/
void removeLast()
{
last = .
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
Need Help!! C++
#include<iostream>
#include"linkedlist.h"
using namespace std;
/**
* @brief Destructor to destroy all nodes and release memory
*/
LinkedList::~LinkedList() {
//TODO: Add code here. Make sure memory is released properly.
}
/**
* @brief Purpose: Checks if the list is empty
* @return true if the list is empty, false otherwise
*/
bool LinkedList::isEmpty() const {
// TODO: Add code here
return count == 0;
}
/**
* @brief Get the number of nodes in the list
* @return int The number of nodes in the list
*/
int LinkedList::length() const{
//TODO: Add code here
}
/**
* @brief Convert the list to a string
*
*/
string LinkedList::toString() {
string str = "[";
Node *ptr = front;
if (ptr != nullptr) {
// Head node is not preceded by separator
str += to_string(ptr->val);
ptr = ptr->next;
}
while (ptr != nullptr) {
str += ", " + to_string(ptr->val);
ptr = ptr->next;
}
str += "]";
return str;
}
/**
* @brief Displays the contents of the list
*/
void LinkedList::displayAll() {
cout << toString() << endl;
}
//TODO: Add comments
void LinkedList::addRear(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
void LinkedList::addFront(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
bool LinkedList::deleteFront(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
//TODO: Add comments
bool LinkedList::deleteRear(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
/* --- harder ones for test 2 and 3 -- */
/**
* @brief Delete a node at a given position from the list. The
* node at position pos is deleted and the value of the deleted node is returned in val.
* The valid range of pos is 1 to count. pos = 1 is the first node, and pos = count is the last node.
* @param pos: position of the node to be deleted
* @param val: it is set to the value of the node to be deleted
* @return true: if the node was deleted successfully
* @return false: if the node was not deleted successfully because the position was out of range
*/
bool LinkedList::deleteAt(int pos, T &val) {
//TODO: Add code here
// check if the pos is valid first, then move the ptr to the rigth positon
// consider the special case of deleting the first node and the last node
// Do not forget to set value.
}
/**
* @brief Insert a value at a specified position in the list. The valid pos is in the range of 1 to
count+1.
* The value will be inserted before the node at the specified position. if pos = 1, the value will be
inserted
* at the front of the list. if pos = count+1, the value will be inserted at the rear of the list.
* @param pos: position to insert the value at.
* @param val: value to insert.
* @return true: if the value was inserte.
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
Merge Sort implementation in C++ The implementation for Mergesort given in Section 7.4 takes
an array as input and soils that array. At the beginning of Section 7.4 there is a simple
pseudocode implementation for sorting a linked list using Mergesort. Implement both a linked
list-based version of Mergesort and the array-based version of Mergesort. and compare and
analyze their running times.
Solution
/* Merger sort array-based version */
/* C program for Merge Sort */
#include
#include
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
/* UTILITY FUNCTIONS */
/* Function to print an array */
void printArray(int A[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", A[i]);
printf(\"\ \");
}
/* Driver program to test above functions */
int main()
{
int arr[] = {12, 11, 13, 5, 6, 7};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf(\"Given array is \ \");
printArray(arr, arr_size);
mergeSort(arr, 0, arr_size - 1);
printf(\"\ Sorted array is \ \");
printArray(arr, arr_size);
return 0;
}
--------------------------------------------------------------------------------------------------------------------
/* merge sort link-list version
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function prototypes */
struct node* SortedMerge(struct node* a, struct node* b);
void FrontBackSplit(struct node* source,
struct node** frontRef, struct node** backRef);
/* sorts the linked list by changing next pointers (not data) */
void MergeSort(struct node** headRef)
{
struct node* head = *headRef;
struct node* a;
struct node* b;
/* Base case -- length 0 or 1 */
if ((head == NULL) || (head->next == NULL))
{
return;
}
/* Split head into \'a\' and \'b\' sublists */
FrontBackSplit(head, &a, &b);
/* Recursively sort the sublists */
MergeSort(&a);
MergeSort(&b);
/* answer = merge the two sorted lists together */
*.
Similar to for initializer_list include ltinitializer_listgt .pdf (20)
0 Suppose that a subsidy plan is introduced for lowincome .pdfajay1317
- Rely as little as possible on automatic stabilizers 19. The paradox of thrift is an example of: - Too
much saving relative to exports - A fallacy of composition - Automatic stabilizers - Fractional
reserve banking 20. If the US dollar purchases more Mexican pesos: - The dollar has depreciated
- The peso has appreciated - Both the dollar and the peso have appreciated - The peso has
depreciated 21. True/False: It is possible for a country to invest more than it saves while running a
balanced fiscal budget and a trade surplus. - True - False.
+ 1D 1W1M3M1Y5Y Your position Shares Market value 15 145.pdfajay1317
- Part (a) State the null hypothesis. H0:m=e H0:me H0:m<e H0:me Part (b) Part (c) Part (d) State
the distribution to use for the test. (Enter your answer in the form z or tdf where df is the degrees
of freedom. Round your answer to two decimal places.) x Part (e) What is the test statistic? (If
using the z distribution round your answer to two decimal places, and if using the t distribution
round your answer to three decimal places.) -- Select-- V= Part(f) What is the p-value? (Round
your answer to four decimal places.) Explain what the p-value means for this problem. If H0 is
false, then there is a chance equal to the -value that the sample mean salary of mechanical
engineers is $300 more than the sample mean salary of electrical engineers. If H0 is true, then
there is a chance equal to the p-value that the sample mean salary of mechanical engineers is
$300 more than the sample mean salary of electrical engineers. If H0 is true, then there is a
chance equal to the p-value that the sample mean salary of mechanical engineers is at least $300
less than the sample mean salary of electrical engineers. If H0 is false, then there is a chance
equal to the p-value that the sample mean salary of mechanical engineers is at least $300 less
than the sample mean salary of electrical engineers..
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdfajay1317
/* # INPUT: a node z in the AVL Tree # OUTPUT: the new root node r of the subtree originally
rooted at z before the restructure/rebalancing at z # PRECONDITION: z is the only unbalanced
node in the subtree that it roots; the difference in height of its children is exactly 2 #
POSTCONDITION: the subtree originally rooted at z is a proper AVL subtree with node heights
properly set AVLTreeMap: : Node* AVLTreeMap::rebalance(AVLTreeMap::Node* z) {
AVLTreeMap::Node* r=z; // Your code here return r;.
AIDS is a diagnostic term applied to HIVinfected persons .pdfajay1317
. 1.1 Based on your understanding of the packaging of DNA, describe the structure displayed in
Figure 1 (5) Figure 1 Two copies of four different kinds of proteins come together to form a
structure with DNA 1.2 Identify and describe the secondary structural elements visible for the
proteins and DNA in Figure 1. Indicate if the structures contain tertiary or quaternary structure and
provide a reasoning for your answer (10) 1.3 Describe and illustrate how you could differentiate
between these three DNA strands using DNA melting experiments: Strand 1:
5AGCGGGGCGGCAGCGCGGAT3 Strand 2: 5ATGCCGATATTTTTAGCGCA3 Strand 3:
5ATTTTAAATTAGCATTTAAT3.
Three Theories of DNA Replication Who were the two scien.pdfajay1317
- In other words, we would take $992,596 today and convert it at today's rate into 99,378,882. -
Next, we would lend the 99,378,882 to the Japanese government at the 2.5% rate. - In 90 days
the Japanese Government would repay us 100MLet X== we need today. Then: X(1+0.025/4)={
100mX=799,378,882. - Hence the $ we would need today to convert into would be: 799,378,882
50.009988==$992,596..
The lemonade stands are perfectly competitive because A t.pdfajay1317
. If, in today's respective markets for one-month, three-month and six-month mortgage coupon
payments, trading determines a market price of ninety-nine and one-half ($99.50) dollars per one
hundred dollars of coupon payment receivable in one month, ninety-eight and one-fourth ($98.25)
dollars today per one hundred dollars ($100.00) of coupon payment receivable in three months,
and ninety-seven and one-fourth ($97.25) dollars per one hundred dollars ($100.00) of coupon
payment receivable in six months. A mortgage lender has just originated a twenty year, interest-
only Canadian mortgage with a balance of $500, 000.00 and an announced annual mortgage
coupon rate, r, of 6%. He offers to sell either you or your classmate, today, a security composed of
a single three-month coupon plus a single six-month coupon, each of which could alternatively be
traded on an individual basis in these markets.
a. What should you offer to pay for this security today?
b. What would your classmate offer to pay for this same security if he used the announced annual
coupon rate of 6% and the Canadian method of converting annual to monthly coupon rates to
calculate its present discounted value?
c. To whom would the lender sell the security?
d. If your classmate buys the security at the price he calculates for its present discounted value,
how much does he gain or lose (in dollars today) relative to what he would have paid by using the
market prices in the three and six coupon markets above?
e. Since you can trade in today's markets for three-month and six-month coupons, you decide you
can make an arbitrage profit from your classmate's purchase by offering to trade each of the three-
month and six-month coupon payments composing the security he now owns. Assuming you and
he limit your trading to just one coupon of each maturity, determine (i) how much of a profit you
could make and (ii) whether you buy or sell the three-month coupon you trade with him and,
analogously, whether you buy or sell the six-month coupon you trade with him.
Please show Calculations..
This program reads a decimal array and outputs each numb.pdfajay1317
. In grading eggs into small, medium, and large, the Nancy Farms packs the eggs that weigh more
than 3.6 ounces in packages marked "large" and the eggs that weigh less than 2.4 ounces into
packages marked "small"; the remainder are packed in packages marked "medium." If a day's
packaging contained 10.2% large and 4.18% small eggs, determine the mean and the standard
deviation for the eggs' weights. Assume that the distribution of the weights is normal..
Two novice business students come to their professor and a.pdfajay1317
- irketiniz zor zamanlardan geiyor ve baz eylerin deimesi gerektiini biliyorsunuz! Bu deiime liderlik
etmek iin gerekli becerilere ve kapasiteye sahip olduunuza inanyorsunuz.
Bu durum nasl bir lider gerektiriyor? Bu liderlik tarznn bileenleri nelerdir ve kanan veya "izle ve
dzelt" tipi bir yneticiden nasl farkldr?.
Un mtodo operativo para administrar el inventario es la i.pdfajay1317
. Jennifer Company has two products: A and B. The company uses activity-based costing. The
estimated total cost and expected activity for each of the three activity cost pools are as follows.
Estimated Expected Activity Activity Cost Pool Cost Product A Product B Total Activity 1 R23 500
400 100 500 Activity 2 R18 000 500 200 700 Activity 3 R34 600 600 300 900 5.1 Calculate the
activity rate under the activity-based costing system for Activity 3. (2) 5.2 Calculate the cost per
unit of Product A under activity-based costing..
- For each of the given standard normal distributions, find the -score (critical value) corresponding
to the indicated shaded area. Round to two decimal places.
a) 0.9591
b) 0.7157
-According to the National Center for Education Statistics, the mean SAT score for the math
portion in the United States in 2021 was = 528 with a standard deviation of = 120.
a) To join the Mathletes competition team, applicants must score in the 95th percentile on the SAT
math test. What is the minimum SAT math score required to join the Mathletes? Round to the
nearest whole number.
b) If a government program offers financial aid for those who score below the 30th percentile, does
a
score of 450 qualify for financial aid? Support your answer with mathematical reasoning.
(6 points) For each of the given standard normal distributions, find the z-score (critical value)
corresponding to the indicated shaded area. Round to two decimal places. a) b) (10 points)
According to the National Center for Education Statistics, the mean SAT score for the ma portion
in the United States in 2021 was =528 with a standard deviation of =120. a) To join the "Mathletes"
competition team, applicants must score in the 95th percentile on the S math test. What is the
minimum SAT math score required to join the Mathletes? Round to the nearest whole number. b)
If a government program offers financial aid for those who score below the 30th percentile, doe
score of 450 qualify for financial aid? Support your answer with mathematical reasoning..
Supongamos que la Tierra gir hacia atrs pero an orbita.pdfajay1317
farkl atma stilinin (kanmak, uzlamak ve rekabet etmek) iliki doyumu zerindeki etkilerini aratrmak
istediimizi hayal edin. liki doyumunun benlik saygs ile rttnn bilindiini kefediyoruz. Bir ANCOVA
yrtmek, hangi iki deiken arasndaki ilikiden kaynaklanan varyans ksmen ortadan kaldracaktr?
Tm deikenler arasndaki ilikiden kaynaklanan varyans ortadan kaldrr.
atma stili ve iliki doyumu
Benlik saygs ve iliki doyumu
Benlik saygs ve atma tarz
Bir aratrma, 50 yayann, dilenci yanlarnda sevimli ve a grnen bir kpek varsa, sokak dilencisine
yalnz olduklar duruma gre daha fazla para verdiini buldu. Yayalarn cinsiyetleri de karlatrld. Aadaki
cmlelerden hangisi bu veriler zerindeki basit etki analizini (ana etkiler) aklar?
Kpek sahibi olmann (evet ya da hayr) balara etkisi ve yaya cinsiyetinin (kadn ya da erkek) balara
etkisi
Dilencinin kpei olduunda balardaki fark (evet veya hayr)
Erkek balar ile kadn balar arasndaki greceli fark
Bir kpee sahip olmann etkisinin (evet veya hayr) ve yaya cinsiyetinin (erkek veya dii) etkisinin balar
zerindeki birleik etkisi
Tm deikenler arasndaki ilikiden
kaynaklanan varyans ortadan
kaldrr.
atma stili ve iliki doyumu
Benlik saygs ve iliki doyumu
Benlik saygs ve atma tarz.
Synthesizes the new DNA strands in the 5 3 direction .pdfajay1317
# Follow the instructions in the code def times_table(num 1) : counter =1 while counter <13 :
print(counter * num 1 ) userinput = int(input("Enter a number")) Do this: # Add code to increment
the counter variable #Add code to call the times_table function with userinput as the argument
here.
returns a new copy of the LinkedList It creates a copy .pdfajay1317
. Elvira es una pintora abstracta con un talento increble pero poca fama. Una de sus pinturas,
titulada Blue Lady 13, es una obra de intenso poder y sensualidad. En 1990, lo vendi a Mega
Company para exhibirlo en la entrada pblica principal del nuevo edificio de la sede de la empresa.
Varios crticos de arte que asistieron a la inauguracin del edificio confundieron la pintura con una
obra perdida de Pablo Picasso. Escribieron sobre ello en las columnas de sus peridicos como si
hubieran hecho un gran descubrimiento. Cuando la gente comenz a inundar el Mega Building
para ver Blue Lady 13, los directores de Mega estaban encantados. Incluso llegaron a colocar un
cartel que deca: Este cuadro, titulado La Dama Azul, probablemente fue pintado por Pablo
Picasso durante su poca azul, ca. 1913. Hay algo que Elvira pueda hacer? Explicar.
el tema es derecho internacional.
Sony Ericsson is a global company that was established in .pdfajay1317
? EXERCISE 40.2 (A joint project) Two people are engaged in a joint project. If each person i puts
in the effort xi, a nonnegative number equal to at most 1 , which costs her c(xi), the outcome of the
project is worth f(x1,x2). The worth of the project is split equally between the two people,
regardless of their effort levels. Formulate this situation as a strategic game. Find the Nash
equilibria of the game when (a)f(x1,x2)=3x1x2 and c(xi)=xi2 for i=1,2, and (b)f(x1,x2)=4x1x2 and c(
xi)=xi for i=1,2. In each case, is there a pair of effort levels that yields both players higher payoffs
than the Nash equilibrium effort levels?.
11 ST segment depression may indicate Ischemia Normal fin.pdfajay1317
) The following table represents total production of goods and services and their prices in a small
country of Macrobia: (Hint: What kinds of goods and services are and are not included in the
GDP?)
Year
2014
2015
Quantity
Price
Quantity
Price
Steel (tons)
50
$220.00
40
$210.00
Bread (loaves)
200
$2.00
210
$3.00
Apples (lbs)
100
$2.00
110
$2.00
Haircuts
40
$10.00
40
$12.50
Calculate Macrobia's real GDP in 2015, using 2014 as a base year. [Hint: use the price index from
part (a) and the nominal GDP from part (b)]. Please include the appropriate calculations to explain
your answer.
($1038 is the correc tanswer but I have no idea why) PLEASE SHOW WORK!
Year 2014 2015
Quantity Price Quantity Price
Steel (tons) 50 $220.00 40 $210.00
Bread (loaves) 200 $2.00 210 $3.00
Apples (lbs) 100 $2.00 110 $2.00
Haircuts 40 $10.00 40 $12.50.
Realice una investigacin adicional para obtener ms infor.pdfajay1317
Discuss the National Patient Safety Goals and their relationship to the national safety standards
Examine safety considerations in the provision of client care. Discuss personal and environmental
factors that create a potential for injury. Describe strategies that can assist in reducing risk of
client injury What are the primary functions of OSHA? When must reporting occur? What is the
mission of NIOSH? What types of injuries are nurses at risk for in the work setting? What are
standard precautions in healthcare? How can needle stick injuries be prevented? What
precautions can the nurse take to avoid latex exposure for both healthcare workers and clients?
What legislation is in place to protect nurses against workplace violence?.
Elvira es una pintora abstracta con un talento increble p.pdfajay1317
* $3 per unit variable; $250,000 fixed each year. The company's $32 unit product cost is computed
as follows: Production and cost data for the first two years of operations are:Required: 1. Using
variable costing, what is the unit product cost for both years? 2. What is the variable costing net
operating income in Year 1 and in Year 2? 3. Reconcile the absorption costing and the variable
costing net operating income figures for each year. Complete this question by entering your
answers in the tabs below. Using variable costing, what is the unit product cost for both
years?What is the variable costing net operating income in Year 1 and in Year 2? (Loss amounts
should be indicated with a minus sign.)Reconcile the absorption costing and the variable costing
net operating income figures for each year..
Programming Assignment 4 Calculate the first 16 Fib.pdfajay1317
- Design a simple Python program with 1 function by drawing a structure diagram with 2 modules:
1 main and 1 function - The example in Topic-8 uses the Hotel background. Your design should be
close to your business topic. You may think about different calculation formulas, if-statement, for-
loop for your assignment to receive good grade. - Follow the structure diagram for Listing 6, and
use computerized drawing tool (Word) to draw your diagram - Please do not start coding before
this assignment received positive feedback - Remember: if the design is wrong, the program is
confusing if not wrong -Submit a Word document that contains the structure diagram.Structure
Diagram (cont'd) - Structure diagram for the Python program in Listing 6. begin{tabular}{|c|} hline
twonumbersmain - Generate - SeaonRoomPrice - Off SeasonRoomPrice - Call function
CalculateAvg - Print the result of two prices hline end{tabular} begin{tabular}{l} CalculateAvg
(Calculate the average of two numbers) - Use two numbers (passed from main) - Calculate the
average of two numbers - Return the result (to main) hline end{tabular} - Use it as the model for
your Assignment-6..
El sndrome X frgil es un trastorno dominante ligado al s.pdfajay1317
* 22 . Name this rhythm atrial fibrillation atrial flutter atrial tachycardia sinus tachycardia* 23. Name
this rhythm 1st degree AV block Sinus Arrhythmia Junctional Rhythm Idioventricular Rhythm*24.
Name this rhythm 1st degree AV block 2nd degree AV block Type 1 (Wenkebach) 2nd degree AV
block Type 2 3rd degree AV block.
In grading eggs into small medium and large the Nancy F.pdfajay1317
[ begin{array}{l} text { scale_x_log} 10()_{text {for } x}^{log operatorname{xIs}}+text { scale_x_log
}() text { scale_y_log } 10()_{text {for } y}^{log text { axis }}+text { scale_y_log }() end{array} ] 8.3
Exercises Problem 8.1: Consider each of the tasks below: - Construct a graphics frame. - Add a
layer of glyphs. - Set an axis label. - Divide the frame into facets. - Change the scale for the frame.
Match each of the following functions from the ggplot2 graphics package with the task it performs.
1. geom_point() 2. geom_histogram() 3. ggplot () 4. scale_y_log 10() 5. ylab() 6. facet_wrap () 7.
geom_segment () 8. xlim() 9. facet_grid() Problem 8.2: Here are several graphics based on the
mosaicData: : CPS85 data table. Write ggplot2 statements that will construct each graphic..
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.
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.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
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?
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
for initializer_list include ltinitializer_listgt .pdf
1. // for initializer_list
#include <initializer_list>
// for ostream
#include <iostream>
// for bidirectional_iterator_tag, prev, next, distance
#include <iterator>
// for ptrdiff_t, size_t, swap
#include <utility>
/************************************************************/
// struct representing our ListNode
//
// contains three data members:
// - data
// - next
// - prev
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
if (begin == nullptr || end == nullptr)
{
2. return;
}
if (begin == end)
{
return;
}
if (begin->prev != nullptr)
{
begin->prev->next = end->next;
}
if (end->next != nullptr)
{
end->next->prev = begin->prev;
}
begin->prev = nullptr;
end->next = nullptr;
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
if (first == nullptr || last == nullptr)
{
return;
}
unhook();
if (first == last)
{
first->prev = this;
last->next = this;
next = first;
prev = last;
} else
{
ListNode* before_first = first->prev;
ListNode* after_last = last->next;
before_first->next = first;
first->prev = before_first;
last->next = after_last;
3. after_last->prev = last;
next = first;
prev = last;
}
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};
/************************************************************/
// Struct representing a List const_iterator
//
// contains a single data member:
// - m_nodePtr
template<typename T>
struct ListConstIterator
{
using value_type = T;
using pointer = const value_type*;
using reference = const value_type&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::bidirectional_iterator_tag;
using Node = const ListNode<value_type>;
public:
// construct from Node
ListConstIterator (Node* n) : m_nodePtr (n)
{
}
// construct from Iterator
ListConstIterator (const ListIterator<T>& i) : m_nodePtr (i.m_nodePtr)
5. <> (const ListConstIterator& i, const ListConstIterator& j);
friend bool operator!=
<> (const ListConstIterator& i, const ListConstIterator& j);
private:
Node* m_nodePtr{nullptr};
friend class List<T>;
friend class ListIterator<T>;
};
template<typename T>
bool
operator== (const ListConstIterator<T>& i, const ListConstIterator<T>& j)
{
return i.m_nodePtr == j.m_nodePtr;
}
// compares the underlying pointers for equality
// [2]
template<typename T>
bool
operator!= (const ListConstIterator<T>& i, const ListConstIterator<T>& j)
{
// TODO -- be sure to not accidently make this an infinite recursive call!
}
/************************************************************/
// Struct representing a List iterator
//
// contains a single data member:
// - m_nodePtr
template<typename T>
struct ListIterator
{
using value_type = T;
using pointer = value_type*;
using reference = value_type&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::bidirectional_iterator_tag;
using Node = ListNode<value_type>;
public:
// construct from Node
ListIterator (Node* n) : m_nodePtr (n)
{
}
reference operator* () const
6. {
return m_nodePtr->data;
}
pointer operator-> () const
{
return &(m_nodePtr->data);
}
// advances to the "next" pointer, returns reference to self
// [2]
ListIterator&
operator++ ()
{
// TODO
}
// advances to the "next" pointer, returns copy of self prior to advancement
ListIterator
operator++ (int)
{
ListIterator copy (*this);
m_nodePtr = m_nodePtr->next;
return copy;
}
// advances to the "prev" pointer, returns reference to self
ListIterator&
operator-- ()
{
m_nodePtr = m_nodePtr->prev;
return *this;
}
// advances to the "prev" pointer, returns copy of self prior to advancement
// [2]
ListIterator
operator-- (int)
{
// TODO
}
friend bool operator==<> (const ListIterator& i, const ListIterator& j);
friend bool operator!=<> (const ListIterator& i, const ListIterator& j);
private:
Node* m_nodePtr{nullptr};
friend class List<T>;
friend class ListConstIterator<T>;
7. };
// compares the underlying pointers for equality
// [2]
template<typename T>
bool
operator== (const ListIterator<T>& i, const ListIterator<T>& j)
{
// TODO -- be sure to not accidently make this an infinite recursive call!
}
template<typename T>
bool
operator!= (const ListIterator<T>& i, const ListIterator<T>& j)
{
return i.m_nodePtr != j.m_nodePtr;
}
Please complete the implementation for the missing parts marked TODO!