Help please!!
(Include your modified DList.java source code file in your homework solution zip archive)
Using
whatever Java IDE you prefer, create a project and add DList.java and DListTest.java to it (these
files are provided
in the Week 6 Source zip archive). Modify DList to implement a method that removes all
occurrences of a specific
integer from the list. Here is the pseudocode:
Method removeAll(In: Integer pData) Returns Nothing
Define index variable i and initialize i to 0
While i < the size of this Dlist Do
If get(i) equals pData Then
remove(i)
Else
Increment i
End If
End While
End Method removeAll
Next, modify DListTest() to add test case 21 which tests that removeAll() works correctly.
WHat more do i need to provide to get help on this???
Solution
/* DListNode.java */
/**
* A DListNode is a node in a DList (doubly-linked list).
*/
class DListNode {
/**
* item references the item stored in the current node.
* prev references the previous node in the DList.
* next references the next node in the DList.
*
* DO NOT CHANGE THE FOLLOWING FIELD DECLARATIONS.
*/
public Object item;
protected DListNode prev;
protected DListNode next;
/**
* DListNode() constructor.
* @param i the item to store in the node.
* @param p the node previous to this node.
* @param n the node following this node.
*/
DListNode(Object i, DListNode p, DListNode n) {
item = i;
prev = p;
next = n;
}
}
/* DList.java */
/**
* A DList is a mutable doubly-linked list ADT. Its implementation is
* circularly-linked and employs a sentinel (dummy) node at the head
* of the list.
*
* DO NOT CHANGE ANY METHOD PROTOTYPES IN THIS FILE.
*/
class DList {
/**
* head references the sentinel node.
* size is the number of items in the list. (The sentinel node does not
* store an item.)
*
* DO NOT CHANGE THE FOLLOWING FIELD DECLARATIONS.
*/
protected DListNode head;
protected int size;
/* DList invariants:
* 1) head != null.
* 2) For any DListNode x in a DList, x.next != null.
* 3) For any DListNode x in a DList, x.prev != null.
* 4) For any DListNode x in a DList, if x.next == y, then y.prev == x.
* 5) For any DListNode x in a DList, if x.prev == y, then y.next == x.
* 6) size is the number of DListNodes, NOT COUNTING the sentinel,
* that can be accessed from the sentinel (head) by a sequence of
* \"next\" references.
*/
/**
* newNode() calls the DListNode constructor. Use this class to allocate
* new DListNodes rather than calling the DListNode constructor directly.
* That way, only this method needs to be overridden if a subclass of DList
* wants to use a different kind of node.
* @param item the item to store in the node.
* @param prev the node previous to this node.
* @param next the node following this node.
*/
protected DListNode newNode(Object item, DListNode prev, DListNode next) {
return new DListNode(item, prev, next);
}
/**
* DList() constructor for an empty DList.
*/
public DList() {
// Your solution here.
head = newNode(null, head, head);
head.prev = head;
head.next = head;
si.
I need help implementing a Stack with this java programming assignme.pdfsauravmanwanicp
I need help implementing a Stack with this java programming assignment:
Given a doubly linked list (code provided below) implement a Stack. You must use the doubly
link list class and utilize it as an object in your implementation of the stack.
A Stack is a Last in First Out (LiFO) structure which translates to the processes of outputting the
last element which was inputted in the collection. The Stack is based on the process of putting
things on top of one another and taking the item on top (think of a stack of papers).
Operations to implement:
push (E): Add an element to the start of the sequence
pop: Remove an element from the start of the sequence
Peek: Return the first element of the sequence without removing it
atIndex(x): Return the element at the given index (x) Or throw an exception if it is out of bound
(if you can control the user input then do that instead)
Size: Return the size of the Stack
isEmpty: Boolean, returns true if the Stack is empty
Empty: Empty the Stack
Code Part 1:
public class DoublyLinkedList{
private DNode head;
private DNode tail;
private int size;
public DoublyLinkedList(){ // construct an empty list
this.tail = new DNode (null, null, this.head);
this.head = new DNode (null, this.tail, null);
this.size = 0;
}
public DoublyLinkedList(DNode next){ // constructs a list
// out of a single node
this.tail = new DNode (null, null, next);
this.head = new DNode (null, next, null);
next.changeNext(this.tail);
next.changePrev(this.head);
this.size = 1;
}
public DoublyLinkedList(Object [] objectArray){ // construct a list out of
// an array
this.tail = new DNode (null, null, this.head);
this.head = new DNode (null, this.tail, null);
DNode temp = this.head;
for (Object e : objectArray)
{
//Anonomus function
new DNode (e, temp.getNext(),temp).insertBetweenNodes(temp, temp.getNext());
temp = temp.getNext();
this.size += 1;
}
}
public void addToFrontofList(Object toAdd){ // Appends the begining
// of the list
DNode temp = new DNode (toAdd, this.head.getNext(), this.head);
this.head.getNext().changePrev(temp);
this.head.changeNext(temp);
this.size += 1;
}
public void addToendofList (Object toAdd) // appends the end of the list
// with a node
{
DNode temp = new DNode (toAdd, this.tail, this.tail.getPrev());
this.tail.getPrev().changeNext(temp);
this.tail.changePrev(temp);
this.size += 1;
}
public void insertAfterNode(DNode current, Object input)// Inserts a new
// a new node after
// current node
{
current.insertAfterNode(input);
this.size += 1;
}
public int getSize() // returns the size of the list
{
return this.size;
}
public String toString()
{
String result = \"\";
for (DNode temp = this.head.getNext();
temp.hasNext(); temp = temp.getNext())
{
result += temp.getValue();
result += \" -> \";
}
result += \"End of list\";
return result;
}
}
and code part2:
public class DNode{
private Object e; // place holder for the type of object the
//collection is storing
private DNode next; // reference to the next node in the sequence
// of.
This is problem is same problem which i submitted on 22017, I just.pdffcaindore
There is a host of sociological and cultural research that paints a robust picture of the effects of
globalization on culture. This Application focuses on the flows of culture between Western and
developing nations. As a practitioner in this global environment, you should be familiar with
these culture effects. Use newspapers, magazines, and the Internet to research cultural changes in
both Western and developing countries due to globalization. Then perform the following tasks:
Outline the cultural aspects of globalization. Take an anthropological, rather than a business,
perspective. Explain how you think understanding culture helps in doing business in today\'s
global economy. Cite resources to justify your response.
Solution
Information technology has penetrated almost every aspect of our lives, “shrinking” our world
into a global village.
Economies and cultures have come closer. People are now aware of the cultures, traditions,
lifestyle, living conditions
prevailing in almost every corner of the world. Interestingly, this is going beyond awareness and
into a state of
integration that is a result of cross-pollinated views, ideologies, products and services.
This evolution is termed as “globalization.”
Culture has many definitions. My own definition is that culture is our collective experience as a
society,
and its impact on our reaction and decision-making relative to every-day facts and
circumstances.
Why is cross-cultural competence critical to your professional future and the viability of your
company?
It’s omnipresent in every business interaction and strategic decision.It is not feasible to be an
expert on
all the world’s cultures. It is possible, however, to incorporate a cross-cultural framework that
improves
cross-cultural understanding and interactions.
Multinational firms whose operations are borderless have to consider the cultural variability of
different regions
of the world and develop cultural understanding. Major cultural constraints encountered by
businesses include local
attitudes, taste preferences, language, religion, management style, gender discrimination, skills,
personalities,
education, etc. To be successful, they need to mold their business actions in accordance with the
local cultural models,
they need to establish a global mindset.
Let’s consider an example of the food giant, McDonald’s. The company enjoys a global
presence; operating in more than
100 countries serving 70 million people every day. Their headquarters and senior management
are U.S.-based but they
entrust their local operations to local managers of the countries they operate in. Operations in
more than 50 percent of
their outlets are franchised. Furthermore, their menus are customized according to cultural
habits and local taste
preferences in every country. It is without a doubt that global thinking and cultural
understanding are both powerful
business tools which allow multinational firms to dominate the local markets and establish a
global pres.
Running Head: Discussion Board 1
Discussion Board 3
Discussion Board
Student’s Name
Institution Affiliation
My topics for this discussion will lean on the immigration and the plight of immigrants. This is a subject that will bring a good platform to form an informative as well as persuasive speech. I will specifically address the value of policy making in the management of immigration trends that are increasing in the USA as well as western countries (Zatz, & Rodriguez, 2015). The topic will be “Do illegal immigrants deserve a hearing in the countries they seek asylum or they should just be deported impartially?” I think this is a contentious issue in the world today.
There are many policies that have been established by various international organizations such as UN in regard to Immigration. The underlying issues in this matter still remain dormant and unresolved. The fundamental question of concern is addressing the parties that should be concerned with this matter. I will be addressing the international community as my audience, particularly the UN, countries. The speech will also include recommendations that will be suggested for handling of the matter. It will also give a discourse of the current situation in different parts of the world such as USA and Europe. This will paint a picture of the dire need of the situation and the dangers that immigrants are facing every day. It will also address the plight of illegal immigrants who I will argue that they deserve humanly just and fair treatment whenever they are met by the hand of the law. The speech is intended to bring an evaluation of the essence of humanity in considering one another and building bridges that alleviate instead of perpetuating human suffering in the world.
References
Zatz, M. S., & Rodriguez, N. (2015). Dreams and nightmares: Immigration policy, youth, and families. University of California Press.
ASS12/assg-12.cppASS12/assg-12.cpp/**
*
* @description Assignment 12 Binary Search Trees
*/
#include<cassert>
#include<iostream>
#include"BinaryTree.hpp"
usingnamespace std;
/** main
* The main entry point for this program. Execution of this program
* will begin with this main function.
*
* @param argc The command line argument count which is the number of
* command line arguments provided by user when they started
* the program.
* @param argv The command line arguments, an array of character
* arrays.
*
* @returns An int value indicating program exit status. Usually 0
* is returned to indicate normal exit and a non-zero value
* is returned to indicate an error condition.
*/
int main(int argc,char** argv)
{
// -----------------------------------------------------------------------
...
Please need help on following program using c++ language. Please inc.pdfnitinarora01
Please need help on following program using c++ language. Please include all header files and
main file with their own title.
Extend the class linkedListType by adding the following operations:
Write a function that returns the info of the kth element of the linked list. If no such element
exists, terminate the program.
Write a function that deletes the kth element of the linked list. If no such element exists,
terminate the program.
Provide the definitions of these functions in the class linkedListType. Also, write a program to
test these functions. (Use either the class unorderedLinkedList or the
class orderedLinkedList to test your function.)
Solution
C++ Code for the given problem is below.....
.....................................................
/*
* C++ Program to Implement Singly Linked List
*/
#include
#include
#include
//using namespace std;
/*
* Node Declaration
*/
typedef struct nodetype
{
int info;
nodetype *next ;
} node;
/*
* Class Declaration
*/
class linkedListType
{
public:
void insfrombeg( node **head, int);
void delfromkth(node **head,int);
void findthekthnode(node *head,int);
void traverse(node *head);
int item,ch,kth;
node *ptr,*head,*temp;
};
/*
* Main :contains menu
*/
void main()
{
int item,ch,kth;
node *ptr,*head,*temp;
linkedListType s1;
clrscr();
while (1)
{
while(1)
{
cout<<\"PRESS (1) FOR INSERT INTO LIST\"<>ch;
switch(ch)
{
case 1:
cout<<\"ENTER THE VALUE \"<>item;
s1.insfrombeg(&head,item);
break;
case 2:
s1.traverse(head);
break;
case 3:
cout<<\"ENTER THE Kth Element which you want\'s to delete\"<>kth;
s1.delfromkth(&head,kth);
break;
case 4:
cout<<\"ENTER THE Kth Element which you want\'s to search \ \"<>kth;
s1.findthekthnode(head,kth);
break;
case 5:
exit(1);
}
}
// getch();
}
}
/*
* Inserting element in beginning
*/
void linkedListType::insfrombeg(node **head,int item)
{
temp= ( node * ) malloc (sizeof( node ));
temp->info= item;
temp->next= NULL;
if(*head == NULL)
{
temp->next= *head;
*head= temp;
}
else
{
temp->next= *head;
*head= temp;
}
}
/*
* Delete element at a given position
*/
void linkedListType::delfromkth(node **head,int kth)
{ node* temp1=*head,*temp2;
if(*head ==NULL)
{
cout<<\"LINK LIST IS EMPTY\ \"<next;
free(temp);
}
else
for(int j=0;jnext;
temp2= temp1->next;
temp1->next=temp2->next;
free(temp2);
}
/*
* Searching an element
*/
void linkedListType::findthekthnode(node *head,int kth)
{
ptr=head;
int i=1;
while((ptr!=NULL))
{
if(i==kth)
{
cout<<\"\ The Element at\"<< kth<< \"position with value is \\t
\"<info<info<next;
i++;
}
}
}
/*
* Traverse Link List
*/
void linkedListType::traverse(node *head)
{
ptr = head;
while((ptr->next)->next!=NULL)
{
cout<info<<\"\\t\";
ptr=ptr->next;
}
cout<
#include
#include
typedef struct nodetype
{
int info;
nodetype *next ;
} node;
int item,ch,kth,total=1;
node *ptr,*head,*temp;
void insfrombeg( node **head, int);
void delfromkth(node **head,int);
void findthekthnode(node *head,int);
void traverse(node *head);
void main()
{
clrscr();
while(1)
{
printf(\"PRESS .
In java , I want you to implement a Data Structure known as a Doubly.pdfaromalcom
In java , I want you to implement a Data Structure known as a Doubly-Ended-Queue. it is a
“fair” data structure in that it implements a FIFO (First In First Out ) behavior. As such, it is
often used to implement various wait lists in computer systems. For example, jobs waiting to use
the CPU, jobs waiting for a printer, jobs waiting to be placed into RAM for execution. In short,
whenever we want a fair strategy for waiting we use queues.
A DEQUE (Doubly-ended-queue) is a related data structure. Although similar to a Queue, it
differs in that it allows for insertions AND deletions from either end of the list (both the front
and the rear).
Your implementation MUST use a doubly-linked-list implementation. You may not use a static
array implementation.
Thus, a Deque is a List but it is one which only concerns itself with the first and last positions for
any insertion or deletion. The 6 operations supported are :
public void insertFront( int item ) - insert the given item (as a node) into the first position of the
Deque.
public void insertRear( int item ) - insert the given item (as a node) into the last position of the
Deque.
public int deleteFront( ) - delete and return the element stored in the first node of the Deque.
public int deletRear( ) – delete and return the element stored in the last node of the Deque.
public boolean isempty( ) - returns true if the Deque is currently empty or false if it is not.
public void printDeque( ) - print the integers from the list, one per line, from the first element
through to the last in order.
Classes
Your program must implement the following 3 classes. public class dequeDriver
This class will contain your program’s main method. It will need to declare a deque object and
process input as indicated below.
Your program should prompt the user for the path of an input file. It should open the file for
input and process it line by line. Each line of the input file will have one of the following forms.
PR
IF
IR
DF
DR
The meanings of each input is as follows:
PR - print the current contents of the deque from front to rear using the printDeque( ) method of
the deque object.
IF - insert the given int value into the front of the deque.
IR - insert the given int value into the rear of the deque.
DF - delete the front value from the deque.
DR – delete the rear element of the deque.
Below is an example input file that your program should be able to process.
PR
IF 4
IF 5
IF 6
IR 7
PR
DR
PR
DF
PR
The output for the input file shown above is :
EMPTY DEQUE
----- Front -----
6
5
4
7
----- Rear -----
----- Front -----
6
5
4
----- Rear -----
----- Front -----
5
4
----- Rear -----
public class dequeNode
This class will implement the linked nodes that will be used to implement the deque itself.
It should have the following protected data members.
protected dequeNode next; // next pointer to next node
protected dequeNode prev; // previous pointer to previous node
protected int val; // the integer value stored within the dequeNod.
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
How do I fix it in LinkedList.java?
LabProgram.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 NoS.
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
So I have this code( StackInAllSocks ) and I implemented the method but I can't seem to figure
out why there isn't anything showing up on the console. It should pop,peek and push b using the
methods from the class called ArrayListTen . The ArrayListTen works fine and compiles the
tested code of Rigth# but for StackInAllSocks it doesn't complete at all. note that file
VodeDodeis not to be changed is just a Node storage area of the array list.
Did I implement the method on StackInAllSocks correctly? if so, should I not use the method
from the ArrayListTen .?
__________________________________________________________________________
: the code is : VodeDodeis
class VodeDode<T> {
private T data;
private VodeDode<T> next;
private VodeDode<T> prev;
public VodeDode(T data) {
this.data = data;
this.next = null;
this.prev = null;}
public T getData() {
return data;}
public void setData(T data) {
this.data = data;}
public VodeDode<T> getNext() {
return this.next;}
public void setNext(VodeDode<T> next) {
this.next = next;}
public VodeDode<T> getPrev() {
return this.prev;}
public void setPrev(VodeDode<T> prev) {
this.prev = prev;}
@Override
public String toString() {
return data.toString();}}
_________________________________________________________________________
CODE that works fine called ArrayListTen:
import java.util.Iterator;
public class ArrayListTen<T> implements Iterable<T> {
private VodeDode<T> head; //beginning of list
private VodeDode<T> tail; //end of list
private int size;
private VodeDode<T> new_item;
public ArrayListTen( ){
this.head = null;
this.tail = null;
this.size = 0;}
public int lenght() {
return size ;}
public T getBegin() {
if (this.head != null) {
return head.getData();}
else { return null;}}
public void addBegin(T value) {
VodeDode<T> newVodeDode =new VodeDode<T>(value);
if (this.head== null) {
head = newVodeDode;
tail =newVodeDode;}
else {VodeDode<T> temp = head;
head = newVodeDode;
head.setNext(temp);}
size++;}
public T removeBegin() {
if(this.head == null) {
return null;}
else {T current = head.getData();
if (tail == head) {
tail = null;
head = null;
} else {
head = head.getNext();
head.setPrev(null);}size--;
return current;}}
public T getEnd() {
if (tail != null) {
return tail.getData();
} else {
return null;}}
public void addEnd(T value) {
VodeDode<T> newVodeDode = new VodeDode<T>(value);
if (this.tail == null) {
head = newVodeDode;
tail = newVodeDode;
} else {
newVodeDode.setPrev(tail);
tail.setNext(newVodeDode);
tail = newVodeDode;}
size++;}
public T removeEnd() {
if(this.tail == null) {
return null;}
else {
T current = tail.getData();//was head.
if (head == tail) {
head = null;
tail = null;
} else {
tail = tail.getPrev();
tail.setNext(null);}
size--;
return current;}}
public T removeBN(T value) {
VodeDode<T> currVodeDode = head;
VodeDode<T> prevVodeDode = null;
while(currVodeDode != null){
if(currVodeDode.getData().equals(value)){
if(prevVodeDode != null){
prevVodeDode.setNext(currVodeDode.getNext());}
else{
head = curr.
I need help implementing a Stack with this java programming assignme.pdfsauravmanwanicp
I need help implementing a Stack with this java programming assignment:
Given a doubly linked list (code provided below) implement a Stack. You must use the doubly
link list class and utilize it as an object in your implementation of the stack.
A Stack is a Last in First Out (LiFO) structure which translates to the processes of outputting the
last element which was inputted in the collection. The Stack is based on the process of putting
things on top of one another and taking the item on top (think of a stack of papers).
Operations to implement:
push (E): Add an element to the start of the sequence
pop: Remove an element from the start of the sequence
Peek: Return the first element of the sequence without removing it
atIndex(x): Return the element at the given index (x) Or throw an exception if it is out of bound
(if you can control the user input then do that instead)
Size: Return the size of the Stack
isEmpty: Boolean, returns true if the Stack is empty
Empty: Empty the Stack
Code Part 1:
public class DoublyLinkedList{
private DNode head;
private DNode tail;
private int size;
public DoublyLinkedList(){ // construct an empty list
this.tail = new DNode (null, null, this.head);
this.head = new DNode (null, this.tail, null);
this.size = 0;
}
public DoublyLinkedList(DNode next){ // constructs a list
// out of a single node
this.tail = new DNode (null, null, next);
this.head = new DNode (null, next, null);
next.changeNext(this.tail);
next.changePrev(this.head);
this.size = 1;
}
public DoublyLinkedList(Object [] objectArray){ // construct a list out of
// an array
this.tail = new DNode (null, null, this.head);
this.head = new DNode (null, this.tail, null);
DNode temp = this.head;
for (Object e : objectArray)
{
//Anonomus function
new DNode (e, temp.getNext(),temp).insertBetweenNodes(temp, temp.getNext());
temp = temp.getNext();
this.size += 1;
}
}
public void addToFrontofList(Object toAdd){ // Appends the begining
// of the list
DNode temp = new DNode (toAdd, this.head.getNext(), this.head);
this.head.getNext().changePrev(temp);
this.head.changeNext(temp);
this.size += 1;
}
public void addToendofList (Object toAdd) // appends the end of the list
// with a node
{
DNode temp = new DNode (toAdd, this.tail, this.tail.getPrev());
this.tail.getPrev().changeNext(temp);
this.tail.changePrev(temp);
this.size += 1;
}
public void insertAfterNode(DNode current, Object input)// Inserts a new
// a new node after
// current node
{
current.insertAfterNode(input);
this.size += 1;
}
public int getSize() // returns the size of the list
{
return this.size;
}
public String toString()
{
String result = \"\";
for (DNode temp = this.head.getNext();
temp.hasNext(); temp = temp.getNext())
{
result += temp.getValue();
result += \" -> \";
}
result += \"End of list\";
return result;
}
}
and code part2:
public class DNode{
private Object e; // place holder for the type of object the
//collection is storing
private DNode next; // reference to the next node in the sequence
// of.
This is problem is same problem which i submitted on 22017, I just.pdffcaindore
There is a host of sociological and cultural research that paints a robust picture of the effects of
globalization on culture. This Application focuses on the flows of culture between Western and
developing nations. As a practitioner in this global environment, you should be familiar with
these culture effects. Use newspapers, magazines, and the Internet to research cultural changes in
both Western and developing countries due to globalization. Then perform the following tasks:
Outline the cultural aspects of globalization. Take an anthropological, rather than a business,
perspective. Explain how you think understanding culture helps in doing business in today\'s
global economy. Cite resources to justify your response.
Solution
Information technology has penetrated almost every aspect of our lives, “shrinking” our world
into a global village.
Economies and cultures have come closer. People are now aware of the cultures, traditions,
lifestyle, living conditions
prevailing in almost every corner of the world. Interestingly, this is going beyond awareness and
into a state of
integration that is a result of cross-pollinated views, ideologies, products and services.
This evolution is termed as “globalization.”
Culture has many definitions. My own definition is that culture is our collective experience as a
society,
and its impact on our reaction and decision-making relative to every-day facts and
circumstances.
Why is cross-cultural competence critical to your professional future and the viability of your
company?
It’s omnipresent in every business interaction and strategic decision.It is not feasible to be an
expert on
all the world’s cultures. It is possible, however, to incorporate a cross-cultural framework that
improves
cross-cultural understanding and interactions.
Multinational firms whose operations are borderless have to consider the cultural variability of
different regions
of the world and develop cultural understanding. Major cultural constraints encountered by
businesses include local
attitudes, taste preferences, language, religion, management style, gender discrimination, skills,
personalities,
education, etc. To be successful, they need to mold their business actions in accordance with the
local cultural models,
they need to establish a global mindset.
Let’s consider an example of the food giant, McDonald’s. The company enjoys a global
presence; operating in more than
100 countries serving 70 million people every day. Their headquarters and senior management
are U.S.-based but they
entrust their local operations to local managers of the countries they operate in. Operations in
more than 50 percent of
their outlets are franchised. Furthermore, their menus are customized according to cultural
habits and local taste
preferences in every country. It is without a doubt that global thinking and cultural
understanding are both powerful
business tools which allow multinational firms to dominate the local markets and establish a
global pres.
Running Head: Discussion Board 1
Discussion Board 3
Discussion Board
Student’s Name
Institution Affiliation
My topics for this discussion will lean on the immigration and the plight of immigrants. This is a subject that will bring a good platform to form an informative as well as persuasive speech. I will specifically address the value of policy making in the management of immigration trends that are increasing in the USA as well as western countries (Zatz, & Rodriguez, 2015). The topic will be “Do illegal immigrants deserve a hearing in the countries they seek asylum or they should just be deported impartially?” I think this is a contentious issue in the world today.
There are many policies that have been established by various international organizations such as UN in regard to Immigration. The underlying issues in this matter still remain dormant and unresolved. The fundamental question of concern is addressing the parties that should be concerned with this matter. I will be addressing the international community as my audience, particularly the UN, countries. The speech will also include recommendations that will be suggested for handling of the matter. It will also give a discourse of the current situation in different parts of the world such as USA and Europe. This will paint a picture of the dire need of the situation and the dangers that immigrants are facing every day. It will also address the plight of illegal immigrants who I will argue that they deserve humanly just and fair treatment whenever they are met by the hand of the law. The speech is intended to bring an evaluation of the essence of humanity in considering one another and building bridges that alleviate instead of perpetuating human suffering in the world.
References
Zatz, M. S., & Rodriguez, N. (2015). Dreams and nightmares: Immigration policy, youth, and families. University of California Press.
ASS12/assg-12.cppASS12/assg-12.cpp/**
*
* @description Assignment 12 Binary Search Trees
*/
#include<cassert>
#include<iostream>
#include"BinaryTree.hpp"
usingnamespace std;
/** main
* The main entry point for this program. Execution of this program
* will begin with this main function.
*
* @param argc The command line argument count which is the number of
* command line arguments provided by user when they started
* the program.
* @param argv The command line arguments, an array of character
* arrays.
*
* @returns An int value indicating program exit status. Usually 0
* is returned to indicate normal exit and a non-zero value
* is returned to indicate an error condition.
*/
int main(int argc,char** argv)
{
// -----------------------------------------------------------------------
...
Please need help on following program using c++ language. Please inc.pdfnitinarora01
Please need help on following program using c++ language. Please include all header files and
main file with their own title.
Extend the class linkedListType by adding the following operations:
Write a function that returns the info of the kth element of the linked list. If no such element
exists, terminate the program.
Write a function that deletes the kth element of the linked list. If no such element exists,
terminate the program.
Provide the definitions of these functions in the class linkedListType. Also, write a program to
test these functions. (Use either the class unorderedLinkedList or the
class orderedLinkedList to test your function.)
Solution
C++ Code for the given problem is below.....
.....................................................
/*
* C++ Program to Implement Singly Linked List
*/
#include
#include
#include
//using namespace std;
/*
* Node Declaration
*/
typedef struct nodetype
{
int info;
nodetype *next ;
} node;
/*
* Class Declaration
*/
class linkedListType
{
public:
void insfrombeg( node **head, int);
void delfromkth(node **head,int);
void findthekthnode(node *head,int);
void traverse(node *head);
int item,ch,kth;
node *ptr,*head,*temp;
};
/*
* Main :contains menu
*/
void main()
{
int item,ch,kth;
node *ptr,*head,*temp;
linkedListType s1;
clrscr();
while (1)
{
while(1)
{
cout<<\"PRESS (1) FOR INSERT INTO LIST\"<>ch;
switch(ch)
{
case 1:
cout<<\"ENTER THE VALUE \"<>item;
s1.insfrombeg(&head,item);
break;
case 2:
s1.traverse(head);
break;
case 3:
cout<<\"ENTER THE Kth Element which you want\'s to delete\"<>kth;
s1.delfromkth(&head,kth);
break;
case 4:
cout<<\"ENTER THE Kth Element which you want\'s to search \ \"<>kth;
s1.findthekthnode(head,kth);
break;
case 5:
exit(1);
}
}
// getch();
}
}
/*
* Inserting element in beginning
*/
void linkedListType::insfrombeg(node **head,int item)
{
temp= ( node * ) malloc (sizeof( node ));
temp->info= item;
temp->next= NULL;
if(*head == NULL)
{
temp->next= *head;
*head= temp;
}
else
{
temp->next= *head;
*head= temp;
}
}
/*
* Delete element at a given position
*/
void linkedListType::delfromkth(node **head,int kth)
{ node* temp1=*head,*temp2;
if(*head ==NULL)
{
cout<<\"LINK LIST IS EMPTY\ \"<next;
free(temp);
}
else
for(int j=0;jnext;
temp2= temp1->next;
temp1->next=temp2->next;
free(temp2);
}
/*
* Searching an element
*/
void linkedListType::findthekthnode(node *head,int kth)
{
ptr=head;
int i=1;
while((ptr!=NULL))
{
if(i==kth)
{
cout<<\"\ The Element at\"<< kth<< \"position with value is \\t
\"<info<info<next;
i++;
}
}
}
/*
* Traverse Link List
*/
void linkedListType::traverse(node *head)
{
ptr = head;
while((ptr->next)->next!=NULL)
{
cout<info<<\"\\t\";
ptr=ptr->next;
}
cout<
#include
#include
typedef struct nodetype
{
int info;
nodetype *next ;
} node;
int item,ch,kth,total=1;
node *ptr,*head,*temp;
void insfrombeg( node **head, int);
void delfromkth(node **head,int);
void findthekthnode(node *head,int);
void traverse(node *head);
void main()
{
clrscr();
while(1)
{
printf(\"PRESS .
In java , I want you to implement a Data Structure known as a Doubly.pdfaromalcom
In java , I want you to implement a Data Structure known as a Doubly-Ended-Queue. it is a
“fair” data structure in that it implements a FIFO (First In First Out ) behavior. As such, it is
often used to implement various wait lists in computer systems. For example, jobs waiting to use
the CPU, jobs waiting for a printer, jobs waiting to be placed into RAM for execution. In short,
whenever we want a fair strategy for waiting we use queues.
A DEQUE (Doubly-ended-queue) is a related data structure. Although similar to a Queue, it
differs in that it allows for insertions AND deletions from either end of the list (both the front
and the rear).
Your implementation MUST use a doubly-linked-list implementation. You may not use a static
array implementation.
Thus, a Deque is a List but it is one which only concerns itself with the first and last positions for
any insertion or deletion. The 6 operations supported are :
public void insertFront( int item ) - insert the given item (as a node) into the first position of the
Deque.
public void insertRear( int item ) - insert the given item (as a node) into the last position of the
Deque.
public int deleteFront( ) - delete and return the element stored in the first node of the Deque.
public int deletRear( ) – delete and return the element stored in the last node of the Deque.
public boolean isempty( ) - returns true if the Deque is currently empty or false if it is not.
public void printDeque( ) - print the integers from the list, one per line, from the first element
through to the last in order.
Classes
Your program must implement the following 3 classes. public class dequeDriver
This class will contain your program’s main method. It will need to declare a deque object and
process input as indicated below.
Your program should prompt the user for the path of an input file. It should open the file for
input and process it line by line. Each line of the input file will have one of the following forms.
PR
IF
IR
DF
DR
The meanings of each input is as follows:
PR - print the current contents of the deque from front to rear using the printDeque( ) method of
the deque object.
IF - insert the given int value into the front of the deque.
IR - insert the given int value into the rear of the deque.
DF - delete the front value from the deque.
DR – delete the rear element of the deque.
Below is an example input file that your program should be able to process.
PR
IF 4
IF 5
IF 6
IR 7
PR
DR
PR
DF
PR
The output for the input file shown above is :
EMPTY DEQUE
----- Front -----
6
5
4
7
----- Rear -----
----- Front -----
6
5
4
----- Rear -----
----- Front -----
5
4
----- Rear -----
public class dequeNode
This class will implement the linked nodes that will be used to implement the deque itself.
It should have the following protected data members.
protected dequeNode next; // next pointer to next node
protected dequeNode prev; // previous pointer to previous node
protected int val; // the integer value stored within the dequeNod.
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
How do I fix it in LinkedList.java?
LabProgram.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 NoS.
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
So I have this code( StackInAllSocks ) and I implemented the method but I can't seem to figure
out why there isn't anything showing up on the console. It should pop,peek and push b using the
methods from the class called ArrayListTen . The ArrayListTen works fine and compiles the
tested code of Rigth# but for StackInAllSocks it doesn't complete at all. note that file
VodeDodeis not to be changed is just a Node storage area of the array list.
Did I implement the method on StackInAllSocks correctly? if so, should I not use the method
from the ArrayListTen .?
__________________________________________________________________________
: the code is : VodeDodeis
class VodeDode<T> {
private T data;
private VodeDode<T> next;
private VodeDode<T> prev;
public VodeDode(T data) {
this.data = data;
this.next = null;
this.prev = null;}
public T getData() {
return data;}
public void setData(T data) {
this.data = data;}
public VodeDode<T> getNext() {
return this.next;}
public void setNext(VodeDode<T> next) {
this.next = next;}
public VodeDode<T> getPrev() {
return this.prev;}
public void setPrev(VodeDode<T> prev) {
this.prev = prev;}
@Override
public String toString() {
return data.toString();}}
_________________________________________________________________________
CODE that works fine called ArrayListTen:
import java.util.Iterator;
public class ArrayListTen<T> implements Iterable<T> {
private VodeDode<T> head; //beginning of list
private VodeDode<T> tail; //end of list
private int size;
private VodeDode<T> new_item;
public ArrayListTen( ){
this.head = null;
this.tail = null;
this.size = 0;}
public int lenght() {
return size ;}
public T getBegin() {
if (this.head != null) {
return head.getData();}
else { return null;}}
public void addBegin(T value) {
VodeDode<T> newVodeDode =new VodeDode<T>(value);
if (this.head== null) {
head = newVodeDode;
tail =newVodeDode;}
else {VodeDode<T> temp = head;
head = newVodeDode;
head.setNext(temp);}
size++;}
public T removeBegin() {
if(this.head == null) {
return null;}
else {T current = head.getData();
if (tail == head) {
tail = null;
head = null;
} else {
head = head.getNext();
head.setPrev(null);}size--;
return current;}}
public T getEnd() {
if (tail != null) {
return tail.getData();
} else {
return null;}}
public void addEnd(T value) {
VodeDode<T> newVodeDode = new VodeDode<T>(value);
if (this.tail == null) {
head = newVodeDode;
tail = newVodeDode;
} else {
newVodeDode.setPrev(tail);
tail.setNext(newVodeDode);
tail = newVodeDode;}
size++;}
public T removeEnd() {
if(this.tail == null) {
return null;}
else {
T current = tail.getData();//was head.
if (head == tail) {
head = null;
tail = null;
} else {
tail = tail.getPrev();
tail.setNext(null);}
size--;
return current;}}
public T removeBN(T value) {
VodeDode<T> currVodeDode = head;
VodeDode<T> prevVodeDode = null;
while(currVodeDode != null){
if(currVodeDode.getData().equals(value)){
if(prevVodeDode != null){
prevVodeDode.setNext(currVodeDode.getNext());}
else{
head = curr.
Java Foundations StackADT-java --- - Defines the interface to a stack.docxVictorXUQGloverl
Java Foundations
StackADT.java
/**
* Defines the interface to a stack collection.
*
* @author Java Foundations
* @version 4.0
*/
public interface StackADT<T> {
/**
* Adds the specified element to the top of this stack.
*
* @param element element to be pushed onto the stack
*/
public void push(T element);
/**
* Removes and returns the top element from this stack.
*
* @return the element removed from the stack
* @throws EmptyCollectionException if the stack is empty
*/
public T pop();
/**
* Returns the top element of this stack without removing it from the stack.
*
* @return the element on top of the stack. It is not removed from the stack
* @throws EmptyCollectionException if the stack is empty
*/
public T peek();
/**
* Returns true if this stack contains no elements.
*
* @return true if the stack is empty, false if the stack is not empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this stack.
*
* @return the number of elements in the stack
*/
public int size();
}
QueueADT.java
/**
* QueueADT defines the interface to a queue collection.
*
* @author Java Foundation
* @version 4.0
*/
public interface QueueADT<T> {
/**
* Adds one element to the rear of this queue.
*
* @param element the element to be added to the rear of the queue
*/
public void enqueue(T element);
/**
* Removes and returns the element at the front of this queue.
*
* @return the element at the front of the queue
* @throws EmptyCollectionException if the queue is empty
*/
public T dequeue();
/**
* Returns without removing the element at the front of this queue.
*
* @return the first element in the queue
* @throws EmptyCollectionException if the queue is empty
*/
public T first();
/**
* Returns true if this queue contains no elements.
*
* @return true if the queue is empty, false if the queue is not empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this queue.
*
* @return the number of elements in the queue
*/
public int size();
}
LinkedDeque.java
public class LinkedDeque<T> implements QueueADT<T>, StackADT<T>, DequeADT<T> {
// inner class for a double linked list node
private class DNode<T> {
private T element;
private DNode<T> prev, next;
}
// data fields for the LinkedDeque class
private DNode<T> front, rear;
private int size;
// deque interface methods
@Override
public void addFirst(T element) {
// create a new node and set it up
DNode<T> newNode = new DNode<T>();
newNode.element = element; // from param to new node obj
newNode.prev = newNode.next = null;
if(this.isEmpty()) {
// we are making the only node in the deque
this.rear = this.front = newNode;
} else {
// there already exists a new node
// so, put the new node before the front node
newNode.next = this.front;
this.front.prev = newNode;
this.front = newNode;
}
this.size++;
}
@Override
public T removeFirst() {
T grabbedElt = this.getFirst(); // checks for empty for us
if.
I need help in writing the test cases of the below methods i.pdfadianantsolutions
I need help in writing the test cases of the below methods in java. The test cases must test
both empty and non empty deque.PLS HELP ME WITH WRITING THE TEST CASES IN
JAVA.ITS URGENT.
package deque;
/**
* A deque implemented using a doubly-linked chain.
*
* @param <T>
* The type of elements contained in the deque.
*/
public class Lab08Deque<T> extends DLinkedDeque<T> {
/**
* Inserts a new item at the front of the deque.
*
* @param newEntry
* the item to insert.
*/
public void addToFront(T newEntry) {
DLNode<T> newNode = new DLNode<T>(newEntry);
if (isEmpty()) {
lastNode = newNode;
}
else {
firstNode.setPreviousNode(newNode);
}
newNode.setNextNode(firstNode);
firstNode = newNode;
size++;
throw new UnsupportedOperationException(
"You have not implemented addToFront() yet");
}
/**
* Insert a new item at the rear of the deque.
*
* @param newEntry
* the item to insert.
*/
public void addToBack(T newEntry) {
DLNode<T> newNode = new DLNode<T>(newEntry);
if (isEmpty()) {
firstNode = newNode;
}
else {
lastNode.setPreviousNode(newNode);
newNode.setPreviousNode(lastNode);
}
lastNode = newNode;
size++;
throw new UnsupportedOperationException(
"You have not implemented addToBack() yet");
}
/**
* Remove the item at the front of the deque.
*
* @return The item that was removed
* @throws EmptyQueueException
* if there is not an element at the front
*/
public T removeFront() {
if (isEmpty()) {
throw new EmptyQueueException();
}
T front = firstNode.getData();
firstNode = firstNode.getNextNode();
if (firstNode == null) {
lastNode = null;
}
else {
firstNode.setPreviousNode(null);
}
throw new UnsupportedOperationException(
"You have not implemented removeFront() yet");
}
/**
* Remove the item at the rear of the deque.
*
* @return The item that was removed
* @throws EmptyQueueException
* if there is no element at the front
*/
public T removeBack() {
if (isEmpty()) {
throw new EmptyQueueException();
}
T data = lastNode.getData();
lastNode = lastNode.getPreviousNode();
if (lastNode == null) {
firstNode = null;
}
else {
lastNode.setPreviousNode(null);
}
throw new UnsupportedOperationException(
"You have not implemented removeBack() yet");
}
/**
* Get the item at the front (the head) of the deque. Does not alter the
* deque.
*
* @return the item at the front of the deque.
* @throws EmptyQueueException
* if no element at the front
*/
public T getFront() {
if (isEmpty()) {
throw new EmptyQueueException();
}
return firstNode.getData();
}
/**
* Get the item at the rear (the tail) of the deque. Does not alter the
* deque.
*
* @return the item at the rear of the deque.
* @throws EmptyQueueException
* if no element at rear
*
*/
public T getBack() {
if (isEmpty()) {
throw new EmptyQueueException();
}
return lastNode.getData();
}
/**
* Check if the deque is empty
*
* @return true if the deque has no items
*/
public boolean isEmpty() {
return size() == 0;
}
/**
* Empty the deque.
*/
public void clear() {
while (!isEmpty()) {
removeFront();
}
}
// -------------------------------.
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
**JAVA** A double-ended queue is a list that allows the addition and removal of items from
either end. One end is arbitrarily called the front and other the rear, but the two ends behave
identically. Specify, design and implement a class for a double-ended queue. Include operations
to check if it is empty and to return the number of items in the list. For each end, include
operations for adding and deleting items. Use doubly linked list for your implementation. Call
your class Deque (pronounced \"deck\").
Solution
//package com.java2novice.ds.queue;
public class DequeDblLinkedListImpl {
private LinkedNode front;
private LinkedNode rear;
public void insertFront(T item){
//add element at the beginning of the queue
System.out.println(\"adding at front: \"+item);
LinkedNode nd = new LinkedNode();
nd.setValue(item);
nd.setNext(front);
if(front != null) front.setPrev(nd);
if(front == null) rear = nd;
front = nd;
}
public void insertRear(T item){
//add element at the end of the queue
System.out.println(\"adding at rear: \"+item);
LinkedNode nd = new LinkedNode();
nd.setValue(item);
nd.setPrev(rear);
if(rear != null) rear.setNext(nd);
if(rear == null) front = nd;
rear = nd;
}
public void removeFront(){
if(front == null){
System.out.println(\"Deque underflow!! unable to remove.\");
return;
}
//remove an item from the beginning of the queue
LinkedNode tmpFront = front.getNext();
if(tmpFront != null) tmpFront.setPrev(null);
if(tmpFront == null) rear = null;
System.out.println(\"removed from front: \"+front.getValue());
front = tmpFront;
}
public int size(){
if(front == null && rear ==null){
return 0;
}
//remove an item from the beginning of the queue
LinkedNode tmpFront = front;
LinkedNode tmpRear = rear;
int i=0;
while(tmpFront != rear)
{
i++;
tmpFront=tmpFront.getNext();
}
i++;
return i;
}
public void removeRear(){
if(rear == null){
System.out.println(\"Deque underflow!! unable to remove.\");
return;
}
//remove an item from the beginning of the queue
LinkedNode tmpRear = rear.getPrev();
if(tmpRear != null) tmpRear.setNext(null);
if(tmpRear == null) front = null;
System.out.println(\"removed from rear: \"+rear.getValue());
rear = tmpRear;
}
public static void main(String a[]){
DequeDblLinkedListImpl deque = new DequeDblLinkedListImpl();
deque.insertFront(34);
deque.insertFront(67);
System.out.println(\"Size of the queue : \"+deque.size());
deque.insertFront(29);
deque.insertFront(765);
deque.removeFront();
deque.removeFront();
deque.removeFront();
deque.insertRear(43);
deque.insertRear(83);
deque.insertRear(84);
deque.insertRear(546);
deque.insertRear(356);
deque.removeRear();
deque.removeRear();
deque.removeRear();
deque.removeRear();
deque.removeFront();
deque.removeFront();
deque.removeFront();
}
}
class LinkedNode{
private LinkedNode prev;
private LinkedNode next;
private T value;
public LinkedNode getPrev() {
return prev;
}
public void setPrev(LinkedNode prev) {
this.prev = prev;
}
public LinkedNode getNext() {
return next;
}
public void setNext(L.
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
JAVA OOP project; desperately need help asap im begging.
Been stuck on this for a week since my OOP skills are not good at all. Due in a couple hours so
im desperate. Codes needed will be provided at the end, thank you.
Codes:
DotChaser.java:
import java.util.*;
public class DotChaser {
public static Random rand = new Random(System.currentTimeMillis());
/**
* A "Thing" moves in a grid world. A TypeA Thing randomly
* decides to turn left or right (or not turn) every "round",
* and, afterward, takes a step forward. A TypeB Thing
* only considers making a random turn every 10th round.
*
* A STATIC CLASS? OH NO! GET IT OUT OF HERE!
*/
public static class Thing {
// dir: 0=North, 1=East, 2=South, 3=West.
// timeSinceLast: this is only important for "TypeB" Things.
public int row, col, dir, timeSinceLast;
public char lab = 'r';
public boolean isTypeB;
}
/**
* YOU'LL NEED TO PUT THIS SOMEWHERE ELSE
* HINT: WOULDN'T IT BE NICE TO HAVE A LIST OR QUEUE SO THAT
* WE DON'T HAVE TO USE NODES HERE?
* This class is for linked lists of Thing's
*/
public static class Node {
public Thing data;
public Node next;
}
// EEEEEK! STATIC METHODS!!! PLEASE FIND THEM A BETTER HOME.
public static void rightTurn(Thing t) {
t.dir = (t.dir + 1) % 4;
}
public static void leftTurn(Thing t) {
t.dir = (t.dir + 3) % 4;
}
public static void maybeTurn(Thing t) {
int i = rand.nextInt(3);
if (t.isTypeB) {
t.timeSinceLast++;
if (t.timeSinceLast == 10) {
t.timeSinceLast = 0;
if (i == 1) {
rightTurn(t);
}
if (i == 2) {
leftTurn(t);
}
}
} else {
if (i == 1) {
rightTurn(t);
}
if (i == 2) {
leftTurn(t);
}
}
}
public static void step(Thing t) {
final int[] dc = {
0, 1, 0, -1
}, dr = {
1, 0, -1, 0
};
t.row += dr[t.dir];
t.col += dc[t.dir];
}
/**
* This static method is ok :)
*/
public static void main(String[] args) {
int N = 200;
if( args.length != 0 )
N = Integer.parseInt(args[0]);
// INSTEAD OF A NODE, CREATE SOMETHING MORE USER-FRIENDLY.
Node L = null;
int count = 0;
while( true ) {
// Every N rounds, add another typeA and typeB Thing.
if( count % N == 0 ) {
// Add a typeA thing to the list.
// (GEE, THAT'S A LOT OF CODE FOR JUST CREATING ONE THING)
Thing tA = new Thing();
tA.row = 45;
tA.col = 50;
Node nA = new Node();
nA.data = tA;
nA.next = L;
L = nA;
// Add a typeB thing to the list
Thing tB = new Thing();
tB.row = 55;
tB.col = 50;
tB.lab = 'b';
tB.isTypeB = true;
Node nB = new Node();
nB.data = tB;
nB.next = L;
L = nB;
}
// Print out each thing.
// (SEEMS LIKE A NICE PRINTALL() METHOD CALL WOULD WORK HERE)
// (SEEMS LIKE A toString() METHOD IN THE CLASS WOULD ALSO BE NICE)
for( Node T = L; T != null; T = T.next )
System.out.println(T.data.row + " " + T.data.col + " " + T.data.lab);
System.out.println("done");
System.out.flush();
// Move each thing.
// (SEEMS LIKE A NICE MOVEALL() METHOD CALL WOULD WORK HERE)
for( Node T = L; T != null; T = T.next ) {
maybeTurn(T.data);
step(T.data);
}
count++;
}
}
}
Lab2_Tester.java
import org.junit.Test;
import static org.junit.Assert.assertEqual.
To complete the task, you need to fill in the missing code. I’ve inc.pdfezycolours78
To complete the task, you need to fill in the missing code. I’ve included code to create an
Iterator. An Iterator is an object that iterates over another object – in this case, a circular linked
list. You can use the .next() method to advance the Iterator to the next item (the first time you
call it, the iterator will travel to node at index 0). Using iterator’s .remove() removes the node the
iterator is currently at. Say that we had a CircularLinkedList that looked like this: A ==> B ==>
C ==> D ==> E ==> Calling .next() three times will advance the iterator to index 2. Calling
.remove() once will remove the node at index 2. A ==> B ==> D ==> E ==> Calling .remove()
once more will remove the node now at index 2. A ==> B ==> E ==> The Iterator methods
handle wrapping around the CircularLinkedList. Be sure to create the iterator using l.iterator()
and after you’ve added all the nodes to the list, where l is your CircularLinkedList
Solution
import java.util.Iterator;
class CircularLinkedList implements Iterable {
// Your variables
// You can include a reference to a tail if you want
Node head;
int size; // BE SURE TO KEEP TRACK OF THE SIZE
// implement this constructor
public CircularLinkedList() {
head=null;
}
// writing helper functions for add and remove, like the book did can help
// but remember, the last element\'s next node will be the head!
// attach a node to the end of the list
// Be sure to handle the adding to an empty list
// always returns true
public boolean add(E e) {
Node newNode=new Node(e);
if(size==0){
head=newNode;
}
else{
Node last=getNode(size-1);
last.next=newNode;
}
newNode.next=head; //last element node is set to head
size++;
return true;
}
// need to handle
// out of bounds
// empty list
// adding to front
// adding to middle
// adding to \"end\"
// REMEMBER TO INCREMENT THE SIZE
public boolean add(int index, E e){
if(index>size) return false;
Node tmp=new Node(e);
if(index==0){
tmp.next=head;
Node last=getNode(size-1);
head=tmp;
last.next=head;
}
else {
Node curr=getNode(index-1);
tmp.next=curr.next;
curr.next=tmp;
}
size++;
return true;
}
// I highly recommend using this helper method
// Return Node found at the specified index
// be sure to handle out of bounds cases
private Node getNode(int index ) {
Node prev=head;
for(int i=0;isize) {
e=null;
}
else if(index==0){
e = head.getElement();
Node last=getNode(size-1);
head=head.next;
last.next=head;
size--;
}
else{
Node prev=getNode(index-1);
Node curr=getNode(index);
e=curr.getElement();
prev.next=curr.next;
size--;
}
return e;
}
// Turns your list into a string
// Useful for debugging
public String toString(){
Node current = head;
StringBuilder result = new StringBuilder();
if(size == 0){
return \"\";
}
if(size == 1) {
return head.getElement().toString();
}
else{
do{
result.append(current.getElement());
result.append(\" ==> \");
current = current.next;
} while(current != head);
}
return result.toString();
}
public Iterator iterator() {
return new ListIterator();
}
/.
Required to augment the authors Binary Search Tree (BST) code to .docxdebishakespeare
Required to augment the author's Binary Search Tree (BST) code to support these new operations. Method names below are merely suggestions. (The author’s class is attached separately in the file called “authordoc”. I just built a simple test tree in the author’s main method which can be used to test the various operations. )
1. AnyType nthElement(int n) -- returns the n-th element (starting from 1) of the in-order traversal of the BST.
2. int rank( AnyType x ) -- returns the "rank" of x. The rank of an element is its position (starting with 1) in an in-order traversal.
3. AnyType median( ) -- returns the median (middle) element in the BST. If the BST contains an even number of elements, returns the smaller of the two medians.
4. boolean isPerfect( ) -- returns true if the BST is a perfect binary tree.
5. boolean isComplete( ) -- returns true if the BST is a complete binary tree.
6. String toString( int nrLevels ) -- generates the level-order output described in the sample output below.
Most of these operations could easily be implemented by performing an in-order traversal inside the BST and perhaps placing the results in an ArrayList. However, such a method is extremely inefficient. Instead, we are going to achieve faster performance by "augmenting" the BST nodes. You will add a new private integer data member ("tree size") to the BinaryNode which stores the size of the tree rooted at that node (including the root). You must develop your own algorithms for these operations, but obviously you will use the new tree size data member to guide your search. Think before you code and think recursively!
These items cover those topics not addressed elsewhere in the project description. (R) indicates a requirement, (H) indicates a hint, and (N) indicates a note.
1. (R) Although we are only using the BST for integers, the BST must remain a generic class.
2. (R) Duplicate values are not allowed. Attempts to insert a duplicate value should be ignored.
3. (R) Attempts to remove non-existent values should be ignored.
4. (R) From a coding perspective, the easiest way to avoid duplicate insertions or attempting to remove non-existent elements is to first call find( ). However, this technique is NOT permitted for two reasons.
Calling find( ) before each insert/remove doubles the running time for these operations and is therefore inefficient.
Recusively coding the insert/remove methods to handle these situations is a great learning experience.
5. (R) The level order print (PRINT command) outputs the value of each node, the size of the tree rooted at that node, and the value of the node's parent in that order, inside parenthesis, separated by commas. (node value, tree size, parent value). Since the root has no parent, print NULL for the root's parent value. For readability, separate the levels with a blank line and print no more than 6 node/size/parent values per line. If a level requires multiple lines, use consecutive lines (without a blank line between the ...
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
Write a Java Class to Implement a Generic Linked List
Your list must be implemented as a singly-linked list of generic nodes, where each Node object
has two instance variables: an object of the “type variable” class, and a pointer to the next node
on the list.
Your class will contain separate methods to handle each of the operations read from a data file
(see II., below)
Your class will also override toString() to return the objects on the list in the order in which they
occur.
Write a Test Class for Your LinkedList Class
Your main method will read list operation instructions from a data file, until end-of-file and call
the appropriate LinkedList method to execute each one.
After each operation is executed, print out the operation and the updated list.
The data file to be used is on the class web site and the operations are:
APPEND X - Append object X to the end of the list
ADD N X - Insert object X as the new Nth element in the list, increasing the size of the list by 1
E.g. Suppose the list is:
head -> 1 -> 2 -> 3 -> 4->null
After ADD 3 7 it would be:
head -> 1 -> 2 -> 7 -> 3 -> 4->null
DELETE N – Remove the Nth object from the list
SWAP M N - Interchange the positions of the Mth and Nth
objects on the list
For credit, the two nodes must actually \"trade places\" in the list, and not merely swap their data
values
REVERSE - Reverse the order of the objects on the list
This must be done by reversing the order of the nodes themselves, rather than by swapping the
data stored
To get credit for your reverse() method, it must use either one of these 2 algorithms:
For each node on the list except the current “head”
node, delete the node and insert it as the new head
Use your swap() method
6. CLEAR – Clear the list (make it empty)
No credit will be given for programs that use any additional data structures – either from the Java
API or programmer defined -, other than your own LinkedList class
txt file:
Solution
//Java Program to Implement Singly Linked List
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/* Class Node */
class Nodes
{
protected Object data;
protected Nodes next;
/* Constructor */
public Nodes()
{
next = null;
data = null;
}
/* Constructor */
public Nodes(Object d,Nodes n)
{
data = d;
next = n;
}
/* Function to set link to next Node */
public void setLink(Nodes n)
{
next = n;
}
/* Function to set data to current Node */
public void setData(Object d)
{
data = d;
}
/* Function to get link to next node */
public Nodes getLink()
{
return next;
}
/* Function to get data from current Node */
public Object getData()
{
return data;
}
}
/* Class linkedList */
class linkList
{
protected Nodes start;
protected Nodes end ;
public int size ;
/* Constructor */
public linkList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isEmpty()
{
return start == null;
}
/* Function to get size of list */
public int getSize()
{
return .
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
hi i have to write a java program involving link lists. i have a problem with the nodes, as it is
posting errors with the nodes.
please help me with this problem. thank you.
public class LinkLists {
/* only need to store a single pointer to the node at the head
* of the list.
* The pointer is null if the list is empty.
* Also record the size of the list.
*/
protected Node head;
/* invariant: size is the number of nodes in the list pointed to by head */
protected int size;
/* no-arguments default constructor creates an empty list */
public LinkLists() {
head = null; // start with an empty list
size = 0;
}
/* accessor method */
public int size() {
return size;
}
/* value to add to the end of the list
*/
public void add(T value) {
head = addAtEnd(head, value);
size++;
}
/* node of the list to which the value should be added
* value to add to the end of the list
*/
private Node addAtEnd(Node node, T value) {
if (node == null) { // special case
return new Node(value, null);
} else if (node.getNext() == null) { // other special case
node.setNext(new Node(value, null));
} else {
addAtEnd(node.getNext(), value);
}
return node;
}
/* iterative implementation of the same method
* value to add to the end of the list
*/
public void add2(T value) {
if (head == null) {
head = new Node(value, null);
} else {
Node node = head; // guaranteed not to be null initially
while (node.getNext() != null) {
node = node.getNext(); // guaranteed not to be null here
}
// now, node.getNext() is guaranteed to be null
// similar to the second special case in addAtEnd
node.setNext(new Node(value, null));
}
size++;
}
public void remove(int position) throws BadItemCountException {
if ((position < 1) || (position > size)) {
throw new
BadItemCountException(\"invalid position \" + position +
\", only 1..\" + size + \" available\");
}
if (position == 1) {
head = head.getNext();
} else {
Node node = head;
for (int i = 2; i < position; i++) {
node = node.getNext();
}
node.setNext(node.getNext().getNext());
}
size--; // one less item
}
public String toString() {
return toString(head);
}
private String toString(Node node) {
if (node == null) {
return \"\";
} else {
return node.getValue() + \"\ \" + toString(node.getNext());
}
}
public static void main(String[] args) {
/* create two empty lists, make sure they print out correctly */
LinkLists list1 = new LinkLists();
LinkLists list2 = new LinkLists();
System.out.println(\"list1 = \'\" + list1 + \"\', list2 = \'\" + list2 + \"\'\");
System.out.println(\"list1.size() = \" + list1.size() +
\", list2.size() = \" + list2.size());
/* insert some items, keep checking */
list1.add(\"hello\");
list1.add(\"world\");
list2.add(\"foo\");
list2.add(\"bar\");
list2.add(\"baz\");
System.out.println(\"list1 = \'\" + list1 + \"\', list2 = \'\" + list2 + \"\'\");
System.out.println(\"list1.size() = \" + list1.size() +
\", list2.size() = \" + list2.size());
/* remove an item at an invalid position */
boolean caught = false;
try {
list2.remove(4);
} catch .
Once you have all the structures working as intended- it is time to co.docxfarrahkur54
Once you have all the structures working as intended, it is time to compare the
performances of the 2. Use runBenchmark() to start.
a. First, generate an increasing number (N) of random integers (1000, 5000, 10000,
50000, 75000, 100000, 500000 or as far as your computing power will let you)
i. Time and print how long it takes to insert the random integers into an initially
empty BST. Do not print the tree.
You can get a random list using the java class Random, located in
java.util.Random. To test the speed of the insertion algorithm, you should use
the System.currentTimeMillis() method, which returns a long that contains the
current time (in milliseconds). Call System.currentTimeMillis() before and after
the algorithm runs and subtract the two times. (Instant.now() is an alternative
way of recording the time.)
ii. Time and print how long it takes to insert the same random integers into an
initially empty AVL tree. Do not print the tree.
iii. If T(N) is the time function, how does the growth of TBST(N) compare with the
growth of TAVL(N)?
Plot a simple graph to of time against N for the two types of BSTs to visualize
your results.
b. Second, generate a list of k random integers. k is also some large value.
i. Time how long it takes to search your various N-node BSTs for all k random
integers. It does not matter whether the search succeeds.
ii. Time how long it takes to search your N-node AVL trees for the same k random
integers.
iii. Compare the growth rates of these two search time-functions with a graph the
same way you did in part a.
public class BinarySearchTree<AnyType extends Comparable<? super AnyType>> {
protected BinaryNode<AnyType> root;
public BinarySearchTree() {
root = null;
}
/**
* Insert into the tree; duplicates are ignored.
*
* @param x the item to insert.
* @param root
* @return
*/
protected BinaryNode<AnyType> insert(AnyType x, BinaryNode<AnyType> root) {
// If the root is null, we've reached an empty leaf node, so we create a new node
// with the value x and return it
if (root == null) {
return new BinaryNode<>(x, null, null);
}
// Compare the value of x to the value stored in the root node
int compareResult = x.compareTo(root.element);
// If x is less than the value stored in the root node, we insert it into the left subtree
if (compareResult < 0) {
root.left = insert(x, root.left);
}
// If x is greater than the value stored in the root node, we insert it into the right subtree
else if (compareResult > 0) {
root.right = insert(x, root.right);
}
// If x is equal to the value stored in the root node, we ignore it since the tree does not allow duplicates
return root;
}
/**
* Counts the number of leaf nodes in this tree.
*
* @param t The root of the tree.
* @return
*/
private int countLeafNodes(BinaryNode<AnyType> root) {
// If the root is null, it means the tree is empty, so we return 0
if (root == null) {
return 0;
}
// If the root has no children, it means it is a leaf node, so we return 1
if (root.left == .
4. The size of instructions can be fixed or variable. What are advant.pdfmumnesh
4. The size of instructions can be fixed or variable. What are advantage and disadvantage of
fixed compared to variable? point) eft 2 20 0 C-4131-28 Add suction 131-26 nvaction 125-2 PC
egister daiess mancion 120-16 date 1 regnter 2 nstructien 31-00 eg stcrs Read U ALLu dela tlata
dvts 02 rstend In the above figure (single-cycle implementation), current instruction is SW S1,
4(S2) (SW: Store Word; current addrss for this instruction is 100 in decimal; S1 and $2 are
initially 8). For redundancy, you should write \"X\" instead of 0 or . You should write the reason
for cach question as well. 5. What is the value of RegDst? (1 point) 6. What is the value of
RegWrite? (I point) 7. What is the value after sign-extension? 1 point) 8. What is the value of
MemRead? (1 point) 9. What is the value of MemtoReg? (1 point) In the above figure, current
instruction is ADDI $1. S2, #-1(which is minus l) (ADDI is ADD Immediate; current address for
this instruction s 100 in decimal and S2 are initially1). For redundancy, you should write “X\',
instead of 0 or 1 . You should write the reason for each question as well. 10. What is the value
(immediate value) of instruction [15-0)? Write the value in 6-bit binary (1 point) 11. What is the
value after sign extension? Write the value in 32-bit binary. (I point) 12. What is the value of
Reg Write? (1 point) 13. What is the value of MemtoReg? (1 point) 2/4
Solution
import java.util.AbstractSet; import java.util.Arrays; import java.util.Iterator; import
java.util.NoSuchElementException; /** * Implementation of an abstract set using an array-
based binary tree. This is * used to help teach binary tree\'s and will have more details explained
in * future lectures. * * @author William J. Collins * @author Matthew Hertz * @param
Data type (which must be Comparable) of the elements in this tree. */ public class
ArrayBinaryTree> extends AbstractSet { /** Entry in the data store where the root node can be
found. */ private static final int ROOT = 0; /** Array used to store the nodes which consist of
this binary tree. */ protected Node[] store; /** Number of elements within the tree. */
protected int size; /** * Initializes this ArrayBinaryTree object to be empty. This creates the
array * in which items will be stored. */ @SuppressWarnings(\"unchecked\") public
ArrayBinaryTree() { store = new Node[63]; size = 0; } /** * Initializes this
ArrayBinaryTree object to contain a shallow copy of a * specified ArrayBinaryTree object.
The worstTime(n) is O(n), where n is the * number of elements in the specified
ArrayBinaryTree object. * * @param otherTree The tree which will be copied to create our
new tree, */ @SuppressWarnings(\"unchecked\") public ArrayBinaryTree(ArrayBinaryTree
otherTree) { store = (Node[]) Arrays.copyOf(otherTree.store, otherTree.store.length); size =
otherTree.size; } public int countLeaves() { } /** * Returns the size of this
ArrayBinaryTree object. * * @return the size of this ArrayBinaryTree object. */
@Overrid.
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
How do I fix it in LinkedList.java?
this is what i did
LabProgram.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 remov.
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
Here is the editable code:
Solution
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
public int size() { return size; }
public boolean isEmpty() { return size == 0; }
public void addFirst(E element) {
Node tmp = new Node(element, head, null);
if(head != null ) {head.prev = tmp;}
head = tmp;
if(tail == null) { tail = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* adds element at the end of the linked list
* @param element
*/
public void addLast(E element) {
Node tmp = new Node(element, null, tail);
if(tail != null) {tail.next = tmp;}
tail = tmp;
if(head == null) { head = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
public void iterateForward(){
System.out.println(\"iterating forward..\");
Node tmp = head;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.next;
}
}
/**
* this method walks backward through the linked list
*/
public void iterateBackward(){
System.out.println(\"iterating backword..\");
Node tmp = tail;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.prev;
}
}
public E removeFirst() {
if (size == 0) throw new NoSuchElementException();
Node tmp = head;
head = head.next;
head.prev = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public E removeLast() {
if (size == 0) throw new NoSuchElementException();
Node tmp = tail;
tail = tail.prev;
tail.next = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public static void main(String a[]){
DoublyLinkedListImpl dll = new DoublyLinkedListImpl();
dll.addFirst(10);
dll.addFirst(34);
dll.addLast(56);
dll.addLast(364);
dll.iterateForward();
dll.removeFirst();
dll.removeLast();
dll.iterateBackward();
}
}
import java.util.Scanner;
/* Class Node */
class Node
{
protected int data;
protected Node next, prev;
/* Constructor */
public Node()
{
next = null;
prev = null;
data = 0;
}
/* Constructor */
public Node(int d, Node n, Node p)
{
data = d;
next = n;
prev = p;
}
/* Function to set link to next node */
public void setLinkNext(Node n)
{
next = n;
}
/* Function to set link to previous node */
public void setLinkPrev(Node p)
{
prev = p;
}
/* Funtion to get link to next node */
public Node getLinkNext()
{
return next;
}
/* Function to get link to previous node */
public Node getLinkPrev()
{
return prev;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Class linkedList */
class linkedList
{
protected Node start;
protected Node end ;
public int size;
/* Constructor */
public linkedList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isE.
Please write in C++ and should be able to compile and debug.Thank yo.pdfajaycosmeticslg
Please write in C++ and should be able to compile and debug.Thank you
Create a class called BinaryTreeDeque. This binary tree implements all of the functionality of
the BinaryTree class, but instead of storing its values in a tree structure, the element values are
stored in a deque, using pointers to maintain the relationship between the binary tree and its node
values. Additionally: deque * getValues() - returns a copy of the deque the current array of
values (which should be in insertion order).
Solution
Following are steps to insert a new node in Complete Binary Tree.
1. If the tree is empty, initialize the root with new node.
2. Else, get the front node of the queue.
…….If the left child of this front node doesn’t exist, set the left child as the new node.
…….else if the right child of this front node doesn’t exist, set the right child as the new node.
3. If the front node has both the left child and right child, Dequeue() it.
4. Enqueue() the new node.
Code :-
-------------------------
binarytreedequeue.h
#ifndef BINARYTREEDEQUE_H
#define BINARYTREEDEQUE_H
// Program for linked implementation of complete binary tree
#include
#include
// For Queue Size
#define SIZE 50
// A tree node
struct node
{
int data;
struct node *right,*left;
};
// A queue node
struct Queue
{
int front, rear;
int size;
struct node* *array;
};
class BinaryTreeDeque
{
public:
BinaryTreeDeque();
struct node* newNode(int data);
struct Queue* createQueue(int size);
int isEmpty(struct Queue* queue);
int isFull(struct Queue* queue);
int hasOnlyOneItem(struct Queue* queue);
void Enqueue(struct node *root, struct Queue* queue);
struct node* Dequeue(struct Queue* queue);
struct node* getFront(struct Queue* queue);
int hasBothChild(struct node* temp);
void insert(struct node **root, int data, struct Queue* queue);
void display(struct Queue* queue);
node * getValues(struct Queue* queue);
};
#endif // BINARYTREEDEQUE_H
binarydequeue.cpp
---------------------------------------
#include \"binarytreedeque.h\"
BinaryTreeDeque::BinaryTreeDeque()
{
}
// A utility function to create a new tree node
struct node* BinaryTreeDeque::newNode(int data)
{
struct node* temp = (struct node*) malloc(sizeof( struct node ));
temp->data = data;
temp->left = temp->right = NULL;
return temp;
}
// A utility function to create a new Queue
struct Queue* BinaryTreeDeque::createQueue(int size)
{
struct Queue* queue = (struct Queue*) malloc(sizeof( struct Queue ));
queue->front = queue->rear = -1;
queue->size = size;
queue->array = (struct node**) malloc(queue->size * sizeof( struct node* ));
int i;
for (i = 0; i < size; ++i)
queue->array[i] = NULL;
return queue;
}
// Standard Queue Functions
int BinaryTreeDeque::isEmpty(struct Queue* queue)
{
return queue->front == -1;
}
int BinaryTreeDeque::isFull(struct Queue* queue)
{ return queue->rear == queue->size - 1; }
int BinaryTreeDeque::hasOnlyOneItem(struct Queue* queue)
{ return queue->front == queue->rear; }
void BinaryTreeDeque::Enqueue(struct node *root, s.
Need Help with this Java Assignment. Program should be done in JAVA .pdfarchiesgallery
Need Help with this Java Assignment. Program should be done in JAVA please
Complete required scripts based on eclipse and troubleshoot the scripts until the tasks are done.
1. Implement a binary search tree (write the code for it), for a height of 2 or higher. Please show
the output if you can Thank you in advance!
Solution
I have compiled this code and checked for errors, worked fine.
Also after the code I have pasted the Output transcript to show what User Inputs I gave and what
all outputs I got.
// Java Program to Implement Binary Tree
import java.util.Scanner;
/* Define Class BinaryTreeNode */
class BinaryTreeNode
{
BinaryTreeNode left, right;
int data;
/* Constructor */
public BinaryTreeNode()
{
left = null;
right = null;
data = 0;
}
/* Constructor */
public BinaryTreeNode(int n)
{
left = null;
right = null;
data = n;
}
/* Function to set left node */
public void setLeft(BinaryTreeNode n)
{
left = n;
}
/* Function to set right node */
public void setRight(BinaryTreeNode n)
{
right = n;
}
/* Function to get left node */
public BinaryTreeNode getLeft()
{
return left;
}
/* Function to get right node */
public BinaryTreeNode getRight()
{
return right;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Define anothe Class Operations to perform required operationns on Binary Tree*/
class Operations
{
private BinaryTreeNode root;
/* Constructor */
public Operations()
{
root = null;
}
/* Function to check if tree is empty */
public boolean isEmpty()
{
return root == null;
}
/* Functions to insert data */
public void insert(int data)
{
root = insert(root, data);
}
/* Function to insert data recursively */
private BinaryTreeNode insert(BinaryTreeNode node, int data)
{
if (node == null)
node = new BinaryTreeNode(data);
else
{
if (node.getRight() == null)
node.right = insert(node.right, data);
else
node.left = insert(node.left, data);
}
return node;
}
/* Function to count number of nodes */
public int countNodes()
{
return countNodes(root);
}
/* Function to count number of nodes recursively */
private int countNodes(BinaryTreeNode r)
{
if (r == null)
return 0;
else
{
int l = 1;
l += countNodes(r.getLeft());
l += countNodes(r.getRight());
return l;
}
}
/* Function to search for an element */
public boolean search(int val)
{
return search(root, val);
}
/* Function to search for an element recursively */
private boolean search(BinaryTreeNode r, int val)
{
if (r.getData() == val)
return true;
if (r.getLeft() != null)
if (search(r.getLeft(), val))
return true;
if (r.getRight() != null)
if (search(r.getRight(), val))
return true;
return false;
}
/* Function for inorder traversal */
public void inorder()
{
inorder(root);
}
private void inorder(BinaryTreeNode r)
{
if (r != null)
{
inorder(r.getLeft());
System.out.print(r.getData() +\" \");
inorder(r.getRight());
}
}
/* Function for preorder traversal */
public void preorder()
{
preorder(root);
}
priva.
File LinkedList.java Defines a doubly-l.pdfConint29
File: LinkedList.java
/**
* Defines a doubly-linked list class
*/
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() {
}
/**
* 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 {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* 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 null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @pos.
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
package singlylinkedlist;
public class Node {
public String value;
public Node next;
public Node(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
SingleyLinkedList.java :
package singlylinkedlist;
import java.io.*;
import java.util.*;
/**
* Defines the interface for a singly-linked list.
*
*/
public interface SinglyLinkedList {
/**
* @return Reference to the first node. If the list is empty, this method
* returns null.
*/
public Node getFirst();
/**
* @return Reference to the last node . If the list is empty, this method
* returns null.
*/
public Node getLast();
/**
* @return Number of nodes in the list
*/
public int size();
/**
* @return true if the list has no nodes; false otherwise
*/
public boolean isEmpty();
/**
* Removes all nodes in the list.
*/
public void clear();
/**
* Inserts a new node with the given value after cursor.
*
* @param cursor
* The node to insert after. Set this to null to insert value as
the
* new first Node.
* @param value
* The value to insert
* @return a reference to the newly inserted Node
*/
public Node insert(Node cursor, String value);
/**
* Inserts a new node with the given value at the "end" of the list.
*
* @param value
* @return a reference to the newly inserted Node
*/
public Node append(String value);
/**
* Removes the node after the specified Node (cursor) from the list.
*
* @param cursor
* A reference to the Node to remove.
*/
public void removeAfter(Node cursor);
/**
* Returns a reference to the first Node containing the key, starting from
the
* given Node.
*
* @param start
* @param key
* @return a reference to the first Node containing the key
*/
public Node find(Node start, String key);
/**
* Prints the values of all the items in a list
*/
public void printWholeList();
}
SinglyLinkedTester.java:
package sbccunittest;
import static java.lang.Math.*;
import static java.lang.System.*;
import static org.apache.commons.lang3.StringUtils.*;
import static org.junit.Assert.*;
import static sbcc.Core.*;
import java.io.*;
import java.lang.reflect.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
import org.apache.commons.lang3.*;
import org.junit.*;
import org.w3c.dom.ranges.*;
import sbcc.*;
import singlylinkedlist.*;
/**
* 09/16/2021
*
* @author sstrenn
*
*/
public class SinglyLinkedListTester {
public static String newline = System.getProperty("line.separator");
public static int totalScore = 0;
public static int extraCredit = 0;
public static boolean isZeroScore = false;
public static String scorePreamble = "";
@BeforeClass
public static void beforeTesting() {
totalScore = 0;
extraCredit = 0;
}
@AfterClass
public static void afterTesting() {
if (isZeroScore) {
totalScore = 0;
extraCredit = 0;
}
println(scorePreamble + "Estimated score (w/o late penalties, etc.) is:
" + totalScore + " out of 25.");
// If the project follows the naming convention, save the results in a
folder on
// the desktop. (Alex Kohanim)
try {
String directory =
substri.
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdffathimalinks
Write the following using java
Given a class ‘Node’ and ‘NodeList’, that contains the below information diagram.
-id: int
-name: String
-next: Node
+Node(id: int, name: String)
+setId(id: int): void
+getId(): int
+setName(name: String) : void
+getName(): String
+setNext(node: Node): void
+getNext(): Node
NodeList
-size: int
-root: Node
+add(node: Node): void
+size(): int
+findNode(node: Node): boolean
Implement add(Node), findNode(Node) and size methods in the NodeList class which is
provided to you. The methods should work as:
Using the following main method:
public static void main(String[] args)
{
NodeList list = new NodeList();
Node node = new Node(1, \"Book\");
Node node2 = new Node(2, \"Lappy\");
list.add(node);
list.add(node2);
System.out.println(\"Length : \"+list.size());
Node node3 = new Node(3, \"Glass\");
Node node4 = new Node(4, \"Pen\");
list.add(node3);
System.out.println(\"Length : \"+list.size());
if(list.findNode(node3)) System.out.println(\"Node found: \"+ node3.getName());
else
System.out.println(\"Node not found: \"+ node3.getName());
if(list.findNode(node4)) System.out.println(\"Node found: \"+ node4.getName());
else
System.out.println(\"Node not found: \"+ node4.getName());
}
Then it should return the following output:
Length : 2
Length : 3
Node found: Glass
Node not found: Pen
The given Node class is:
public class Node
{
private int id = 0;
private String name = \"\";
private Node next;
public Node(int id, String name)
{
this.id = id;
this.name = name;
this.next = null;
}
public Node getNext()
{
return next;
}
public void setNext(Node node)
{
this.next = node
}
public int getId()
{
return id;
{
public void setId(int id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String toString()
{
return \"ID : \"+this.id+\" Name : \"+this.name;
}
}
The given NodeList class is:
public class NodeList
{
private int size = 0;
private Node root = null;
/*
* It has to take a new Node and add that to the next address of previous Node.
* If the list is empty, assign it as the \"root\"
* @Param - Node
*/
public void add(Node node)
{
// Implement this method!!!
}
/*
* It has to return the size of the NodeList
*
* @return size
*/
public int size()
{
// Implement this method!!!
}
/*
* It has to take a Node and checks if the node is in the list.
* If it finds the node, it returns true, otherwise false
*
* @param - Node
* @return boolean true/false
*/
public boolean findNode(Node node)
{
// Implement this method!!!
}
}Node
-id: int
-name: String
-next: Node
+Node(id: int, name: String)
+setId(id: int): void
+getId(): int
+setName(name: String) : void
+getName(): String
+setNext(node: Node): void
+getNext(): Node
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
############ Node.java #############
public class Node
{
private int id = 0;
private String name = \"\";
private Node next;
public Node(int id, String name)
{
this.id = id;
this..
How does an open source operating system like Linux® affect Internet.pdfjyothimuppasani1
How does an open source operating system like Linux® affect Internet security and safety?
Solution
Since open source operating system\'s code is available to all,it\'s provides an easy access to
hackers and potential misusers which affects safety of such systems.
The non stable nature of Open source operating system also can be considered an important
factor that affects the Security.This is because Developers all over the globe modify the code and
thus the code is not stable and it becomes vulnerable to security threats.
Even if patches are introduced from time to time,mostly after an attack or so but due to large
flavours or distributions of open source software, some flavours are left without patches that
makes them vulnerable to attacks.
Also,The administration of open source operating system Servers also plays an important factor
in Internet Security. Since it is known that for example,Linux Server administration is more
difficult and when multiple ports are open it is sometimes not possible to handle an attack or
security threat immediately.
But then as it is said that every coin has two sides, Sometimes it is considered that Open Source
Systems like Linux are more secure because of the following reasons :.
how can I replace the Newsfeed text with a custom on in SharePoi.pdfjyothimuppasani1
how can I replace the \"Newsfeed\" text with a custom on in SharePoint 365.
(Newsfeed Webpart)
Solution
First of all there are some differences between sharepoint and office 365. SharePoint has 4
versions still in active use : SharePoint 2007,2010,2016 and office 365. Office 365 released in
2011 With SharePoint2010 interface. Office 365 hav a various exclusive features like NextGen
Portals (Out of the box “ready to go” portals), Delve (A technology based on Office Graph that
presents “relevant information” to you based on your actions and interactions with colleague
files), Sway (A presentation web par that allows users to combine text, images and videos locally
and from the wider internet to create a usable website.), Yammer Integration (Yammer is the
enterprise social network that\'s being gradually rolled into all Office 365 features.) anf Office
365 Groups.
A custom CSS included in SharePoint master page in order to customize Newsfeed Web Part.
the code is:
.ms-microfeed-siteFeedTitleArea
{
background-color: silver;
padding-left: 20px;
text-transform:uppercase;
padding-bottom: 3px;
padding-top: 2px;
margin-bottom: 5px;
}
.ms-microfeed-siteFeedMicroBlogPart
{
margin-bottom: 2px;
}
.ms-microfeed-siteFeedTitleLabel
{
color: red !important;
}
.ms-microfeed-threadsDiv
{
height: 250px;
overflow-y: auto;
overflow-x: hidden;
}
.ms-microfeed-thread
{
max-width: 435px;
margin-bottom: 10px;
}
.ms-microfeed-replyArea
{
max-width: 375px;
min-width: 300px;
}
.ms-microfeed-attachmentButton
{
padding-top: 2px;
padding-bottom: 2px;
display: block;
}
.ms-microfeed-postButton
{
padding-top: 2px;
padding-bottom: 2px;
}
.ms-microfeed-postButtonSpan
{
margin-top: 2px;
}
.ms-microfeed-postBox
{
height: 20px;
}
Apart from this we can also hide controls, for this first we need to activate Site Feed feature, to
do this go to site settings->Manage Site Features and activate it
script for hide controls
I used the following CSS classes and its worked.
.ms-microfeed-cancelButton{
background-color: #fcfcfc !important;
border: 1px solid #d4d4d4 !important;
-moz-border-radius: 10px !important;
-webkit-border-radius: 10px !important;
border-radius: 10px !important;
color: #00a6d9 !important;
height: 22px !important;
padding-top: 3px !important;
width: 78px !important;
font-family: Arial !important;
font-size: 11px!important;
font-weight: normal !important;
}
.ms-microfeed-siteFeedTitleArea
{
background-color: silver;
padding-left: 20px;
text-transform:uppercase;
padding-bottom: 3px;
padding-top: 2px;
margin-bottom: 5px;
}
.ms-microfeed-siteFeedMicroBlogPart
{
margin-bottom: 2px;
}
.ms-microfeed-siteFeedTitleLabel
{
color: red !important;
}
.ms-microfeed-threadsDiv
{
height: 250px;
overflow-y: auto;
overflow-x: hidden;
}
.ms-microfeed-thread
{
max-width: 435px;
margin-bottom: 10px;
}
.ms-microfeed-replyArea
{
max-width: 375px;
min-width: 300px;
}
.ms-microfeed-attachmentButton
{
padding-top: 2px;
padding-bottom: 2px;
padding-bottom: 2px;
display: block;
}
.ms-microfeed-pos.
More Related Content
Similar to Help please!!(Include your modified DList.java source code file in.pdf
Java Foundations StackADT-java --- - Defines the interface to a stack.docxVictorXUQGloverl
Java Foundations
StackADT.java
/**
* Defines the interface to a stack collection.
*
* @author Java Foundations
* @version 4.0
*/
public interface StackADT<T> {
/**
* Adds the specified element to the top of this stack.
*
* @param element element to be pushed onto the stack
*/
public void push(T element);
/**
* Removes and returns the top element from this stack.
*
* @return the element removed from the stack
* @throws EmptyCollectionException if the stack is empty
*/
public T pop();
/**
* Returns the top element of this stack without removing it from the stack.
*
* @return the element on top of the stack. It is not removed from the stack
* @throws EmptyCollectionException if the stack is empty
*/
public T peek();
/**
* Returns true if this stack contains no elements.
*
* @return true if the stack is empty, false if the stack is not empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this stack.
*
* @return the number of elements in the stack
*/
public int size();
}
QueueADT.java
/**
* QueueADT defines the interface to a queue collection.
*
* @author Java Foundation
* @version 4.0
*/
public interface QueueADT<T> {
/**
* Adds one element to the rear of this queue.
*
* @param element the element to be added to the rear of the queue
*/
public void enqueue(T element);
/**
* Removes and returns the element at the front of this queue.
*
* @return the element at the front of the queue
* @throws EmptyCollectionException if the queue is empty
*/
public T dequeue();
/**
* Returns without removing the element at the front of this queue.
*
* @return the first element in the queue
* @throws EmptyCollectionException if the queue is empty
*/
public T first();
/**
* Returns true if this queue contains no elements.
*
* @return true if the queue is empty, false if the queue is not empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this queue.
*
* @return the number of elements in the queue
*/
public int size();
}
LinkedDeque.java
public class LinkedDeque<T> implements QueueADT<T>, StackADT<T>, DequeADT<T> {
// inner class for a double linked list node
private class DNode<T> {
private T element;
private DNode<T> prev, next;
}
// data fields for the LinkedDeque class
private DNode<T> front, rear;
private int size;
// deque interface methods
@Override
public void addFirst(T element) {
// create a new node and set it up
DNode<T> newNode = new DNode<T>();
newNode.element = element; // from param to new node obj
newNode.prev = newNode.next = null;
if(this.isEmpty()) {
// we are making the only node in the deque
this.rear = this.front = newNode;
} else {
// there already exists a new node
// so, put the new node before the front node
newNode.next = this.front;
this.front.prev = newNode;
this.front = newNode;
}
this.size++;
}
@Override
public T removeFirst() {
T grabbedElt = this.getFirst(); // checks for empty for us
if.
I need help in writing the test cases of the below methods i.pdfadianantsolutions
I need help in writing the test cases of the below methods in java. The test cases must test
both empty and non empty deque.PLS HELP ME WITH WRITING THE TEST CASES IN
JAVA.ITS URGENT.
package deque;
/**
* A deque implemented using a doubly-linked chain.
*
* @param <T>
* The type of elements contained in the deque.
*/
public class Lab08Deque<T> extends DLinkedDeque<T> {
/**
* Inserts a new item at the front of the deque.
*
* @param newEntry
* the item to insert.
*/
public void addToFront(T newEntry) {
DLNode<T> newNode = new DLNode<T>(newEntry);
if (isEmpty()) {
lastNode = newNode;
}
else {
firstNode.setPreviousNode(newNode);
}
newNode.setNextNode(firstNode);
firstNode = newNode;
size++;
throw new UnsupportedOperationException(
"You have not implemented addToFront() yet");
}
/**
* Insert a new item at the rear of the deque.
*
* @param newEntry
* the item to insert.
*/
public void addToBack(T newEntry) {
DLNode<T> newNode = new DLNode<T>(newEntry);
if (isEmpty()) {
firstNode = newNode;
}
else {
lastNode.setPreviousNode(newNode);
newNode.setPreviousNode(lastNode);
}
lastNode = newNode;
size++;
throw new UnsupportedOperationException(
"You have not implemented addToBack() yet");
}
/**
* Remove the item at the front of the deque.
*
* @return The item that was removed
* @throws EmptyQueueException
* if there is not an element at the front
*/
public T removeFront() {
if (isEmpty()) {
throw new EmptyQueueException();
}
T front = firstNode.getData();
firstNode = firstNode.getNextNode();
if (firstNode == null) {
lastNode = null;
}
else {
firstNode.setPreviousNode(null);
}
throw new UnsupportedOperationException(
"You have not implemented removeFront() yet");
}
/**
* Remove the item at the rear of the deque.
*
* @return The item that was removed
* @throws EmptyQueueException
* if there is no element at the front
*/
public T removeBack() {
if (isEmpty()) {
throw new EmptyQueueException();
}
T data = lastNode.getData();
lastNode = lastNode.getPreviousNode();
if (lastNode == null) {
firstNode = null;
}
else {
lastNode.setPreviousNode(null);
}
throw new UnsupportedOperationException(
"You have not implemented removeBack() yet");
}
/**
* Get the item at the front (the head) of the deque. Does not alter the
* deque.
*
* @return the item at the front of the deque.
* @throws EmptyQueueException
* if no element at the front
*/
public T getFront() {
if (isEmpty()) {
throw new EmptyQueueException();
}
return firstNode.getData();
}
/**
* Get the item at the rear (the tail) of the deque. Does not alter the
* deque.
*
* @return the item at the rear of the deque.
* @throws EmptyQueueException
* if no element at rear
*
*/
public T getBack() {
if (isEmpty()) {
throw new EmptyQueueException();
}
return lastNode.getData();
}
/**
* Check if the deque is empty
*
* @return true if the deque has no items
*/
public boolean isEmpty() {
return size() == 0;
}
/**
* Empty the deque.
*/
public void clear() {
while (!isEmpty()) {
removeFront();
}
}
// -------------------------------.
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
**JAVA** A double-ended queue is a list that allows the addition and removal of items from
either end. One end is arbitrarily called the front and other the rear, but the two ends behave
identically. Specify, design and implement a class for a double-ended queue. Include operations
to check if it is empty and to return the number of items in the list. For each end, include
operations for adding and deleting items. Use doubly linked list for your implementation. Call
your class Deque (pronounced \"deck\").
Solution
//package com.java2novice.ds.queue;
public class DequeDblLinkedListImpl {
private LinkedNode front;
private LinkedNode rear;
public void insertFront(T item){
//add element at the beginning of the queue
System.out.println(\"adding at front: \"+item);
LinkedNode nd = new LinkedNode();
nd.setValue(item);
nd.setNext(front);
if(front != null) front.setPrev(nd);
if(front == null) rear = nd;
front = nd;
}
public void insertRear(T item){
//add element at the end of the queue
System.out.println(\"adding at rear: \"+item);
LinkedNode nd = new LinkedNode();
nd.setValue(item);
nd.setPrev(rear);
if(rear != null) rear.setNext(nd);
if(rear == null) front = nd;
rear = nd;
}
public void removeFront(){
if(front == null){
System.out.println(\"Deque underflow!! unable to remove.\");
return;
}
//remove an item from the beginning of the queue
LinkedNode tmpFront = front.getNext();
if(tmpFront != null) tmpFront.setPrev(null);
if(tmpFront == null) rear = null;
System.out.println(\"removed from front: \"+front.getValue());
front = tmpFront;
}
public int size(){
if(front == null && rear ==null){
return 0;
}
//remove an item from the beginning of the queue
LinkedNode tmpFront = front;
LinkedNode tmpRear = rear;
int i=0;
while(tmpFront != rear)
{
i++;
tmpFront=tmpFront.getNext();
}
i++;
return i;
}
public void removeRear(){
if(rear == null){
System.out.println(\"Deque underflow!! unable to remove.\");
return;
}
//remove an item from the beginning of the queue
LinkedNode tmpRear = rear.getPrev();
if(tmpRear != null) tmpRear.setNext(null);
if(tmpRear == null) front = null;
System.out.println(\"removed from rear: \"+rear.getValue());
rear = tmpRear;
}
public static void main(String a[]){
DequeDblLinkedListImpl deque = new DequeDblLinkedListImpl();
deque.insertFront(34);
deque.insertFront(67);
System.out.println(\"Size of the queue : \"+deque.size());
deque.insertFront(29);
deque.insertFront(765);
deque.removeFront();
deque.removeFront();
deque.removeFront();
deque.insertRear(43);
deque.insertRear(83);
deque.insertRear(84);
deque.insertRear(546);
deque.insertRear(356);
deque.removeRear();
deque.removeRear();
deque.removeRear();
deque.removeRear();
deque.removeFront();
deque.removeFront();
deque.removeFront();
}
}
class LinkedNode{
private LinkedNode prev;
private LinkedNode next;
private T value;
public LinkedNode getPrev() {
return prev;
}
public void setPrev(LinkedNode prev) {
this.prev = prev;
}
public LinkedNode getNext() {
return next;
}
public void setNext(L.
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
JAVA OOP project; desperately need help asap im begging.
Been stuck on this for a week since my OOP skills are not good at all. Due in a couple hours so
im desperate. Codes needed will be provided at the end, thank you.
Codes:
DotChaser.java:
import java.util.*;
public class DotChaser {
public static Random rand = new Random(System.currentTimeMillis());
/**
* A "Thing" moves in a grid world. A TypeA Thing randomly
* decides to turn left or right (or not turn) every "round",
* and, afterward, takes a step forward. A TypeB Thing
* only considers making a random turn every 10th round.
*
* A STATIC CLASS? OH NO! GET IT OUT OF HERE!
*/
public static class Thing {
// dir: 0=North, 1=East, 2=South, 3=West.
// timeSinceLast: this is only important for "TypeB" Things.
public int row, col, dir, timeSinceLast;
public char lab = 'r';
public boolean isTypeB;
}
/**
* YOU'LL NEED TO PUT THIS SOMEWHERE ELSE
* HINT: WOULDN'T IT BE NICE TO HAVE A LIST OR QUEUE SO THAT
* WE DON'T HAVE TO USE NODES HERE?
* This class is for linked lists of Thing's
*/
public static class Node {
public Thing data;
public Node next;
}
// EEEEEK! STATIC METHODS!!! PLEASE FIND THEM A BETTER HOME.
public static void rightTurn(Thing t) {
t.dir = (t.dir + 1) % 4;
}
public static void leftTurn(Thing t) {
t.dir = (t.dir + 3) % 4;
}
public static void maybeTurn(Thing t) {
int i = rand.nextInt(3);
if (t.isTypeB) {
t.timeSinceLast++;
if (t.timeSinceLast == 10) {
t.timeSinceLast = 0;
if (i == 1) {
rightTurn(t);
}
if (i == 2) {
leftTurn(t);
}
}
} else {
if (i == 1) {
rightTurn(t);
}
if (i == 2) {
leftTurn(t);
}
}
}
public static void step(Thing t) {
final int[] dc = {
0, 1, 0, -1
}, dr = {
1, 0, -1, 0
};
t.row += dr[t.dir];
t.col += dc[t.dir];
}
/**
* This static method is ok :)
*/
public static void main(String[] args) {
int N = 200;
if( args.length != 0 )
N = Integer.parseInt(args[0]);
// INSTEAD OF A NODE, CREATE SOMETHING MORE USER-FRIENDLY.
Node L = null;
int count = 0;
while( true ) {
// Every N rounds, add another typeA and typeB Thing.
if( count % N == 0 ) {
// Add a typeA thing to the list.
// (GEE, THAT'S A LOT OF CODE FOR JUST CREATING ONE THING)
Thing tA = new Thing();
tA.row = 45;
tA.col = 50;
Node nA = new Node();
nA.data = tA;
nA.next = L;
L = nA;
// Add a typeB thing to the list
Thing tB = new Thing();
tB.row = 55;
tB.col = 50;
tB.lab = 'b';
tB.isTypeB = true;
Node nB = new Node();
nB.data = tB;
nB.next = L;
L = nB;
}
// Print out each thing.
// (SEEMS LIKE A NICE PRINTALL() METHOD CALL WOULD WORK HERE)
// (SEEMS LIKE A toString() METHOD IN THE CLASS WOULD ALSO BE NICE)
for( Node T = L; T != null; T = T.next )
System.out.println(T.data.row + " " + T.data.col + " " + T.data.lab);
System.out.println("done");
System.out.flush();
// Move each thing.
// (SEEMS LIKE A NICE MOVEALL() METHOD CALL WOULD WORK HERE)
for( Node T = L; T != null; T = T.next ) {
maybeTurn(T.data);
step(T.data);
}
count++;
}
}
}
Lab2_Tester.java
import org.junit.Test;
import static org.junit.Assert.assertEqual.
To complete the task, you need to fill in the missing code. I’ve inc.pdfezycolours78
To complete the task, you need to fill in the missing code. I’ve included code to create an
Iterator. An Iterator is an object that iterates over another object – in this case, a circular linked
list. You can use the .next() method to advance the Iterator to the next item (the first time you
call it, the iterator will travel to node at index 0). Using iterator’s .remove() removes the node the
iterator is currently at. Say that we had a CircularLinkedList that looked like this: A ==> B ==>
C ==> D ==> E ==> Calling .next() three times will advance the iterator to index 2. Calling
.remove() once will remove the node at index 2. A ==> B ==> D ==> E ==> Calling .remove()
once more will remove the node now at index 2. A ==> B ==> E ==> The Iterator methods
handle wrapping around the CircularLinkedList. Be sure to create the iterator using l.iterator()
and after you’ve added all the nodes to the list, where l is your CircularLinkedList
Solution
import java.util.Iterator;
class CircularLinkedList implements Iterable {
// Your variables
// You can include a reference to a tail if you want
Node head;
int size; // BE SURE TO KEEP TRACK OF THE SIZE
// implement this constructor
public CircularLinkedList() {
head=null;
}
// writing helper functions for add and remove, like the book did can help
// but remember, the last element\'s next node will be the head!
// attach a node to the end of the list
// Be sure to handle the adding to an empty list
// always returns true
public boolean add(E e) {
Node newNode=new Node(e);
if(size==0){
head=newNode;
}
else{
Node last=getNode(size-1);
last.next=newNode;
}
newNode.next=head; //last element node is set to head
size++;
return true;
}
// need to handle
// out of bounds
// empty list
// adding to front
// adding to middle
// adding to \"end\"
// REMEMBER TO INCREMENT THE SIZE
public boolean add(int index, E e){
if(index>size) return false;
Node tmp=new Node(e);
if(index==0){
tmp.next=head;
Node last=getNode(size-1);
head=tmp;
last.next=head;
}
else {
Node curr=getNode(index-1);
tmp.next=curr.next;
curr.next=tmp;
}
size++;
return true;
}
// I highly recommend using this helper method
// Return Node found at the specified index
// be sure to handle out of bounds cases
private Node getNode(int index ) {
Node prev=head;
for(int i=0;isize) {
e=null;
}
else if(index==0){
e = head.getElement();
Node last=getNode(size-1);
head=head.next;
last.next=head;
size--;
}
else{
Node prev=getNode(index-1);
Node curr=getNode(index);
e=curr.getElement();
prev.next=curr.next;
size--;
}
return e;
}
// Turns your list into a string
// Useful for debugging
public String toString(){
Node current = head;
StringBuilder result = new StringBuilder();
if(size == 0){
return \"\";
}
if(size == 1) {
return head.getElement().toString();
}
else{
do{
result.append(current.getElement());
result.append(\" ==> \");
current = current.next;
} while(current != head);
}
return result.toString();
}
public Iterator iterator() {
return new ListIterator();
}
/.
Required to augment the authors Binary Search Tree (BST) code to .docxdebishakespeare
Required to augment the author's Binary Search Tree (BST) code to support these new operations. Method names below are merely suggestions. (The author’s class is attached separately in the file called “authordoc”. I just built a simple test tree in the author’s main method which can be used to test the various operations. )
1. AnyType nthElement(int n) -- returns the n-th element (starting from 1) of the in-order traversal of the BST.
2. int rank( AnyType x ) -- returns the "rank" of x. The rank of an element is its position (starting with 1) in an in-order traversal.
3. AnyType median( ) -- returns the median (middle) element in the BST. If the BST contains an even number of elements, returns the smaller of the two medians.
4. boolean isPerfect( ) -- returns true if the BST is a perfect binary tree.
5. boolean isComplete( ) -- returns true if the BST is a complete binary tree.
6. String toString( int nrLevels ) -- generates the level-order output described in the sample output below.
Most of these operations could easily be implemented by performing an in-order traversal inside the BST and perhaps placing the results in an ArrayList. However, such a method is extremely inefficient. Instead, we are going to achieve faster performance by "augmenting" the BST nodes. You will add a new private integer data member ("tree size") to the BinaryNode which stores the size of the tree rooted at that node (including the root). You must develop your own algorithms for these operations, but obviously you will use the new tree size data member to guide your search. Think before you code and think recursively!
These items cover those topics not addressed elsewhere in the project description. (R) indicates a requirement, (H) indicates a hint, and (N) indicates a note.
1. (R) Although we are only using the BST for integers, the BST must remain a generic class.
2. (R) Duplicate values are not allowed. Attempts to insert a duplicate value should be ignored.
3. (R) Attempts to remove non-existent values should be ignored.
4. (R) From a coding perspective, the easiest way to avoid duplicate insertions or attempting to remove non-existent elements is to first call find( ). However, this technique is NOT permitted for two reasons.
Calling find( ) before each insert/remove doubles the running time for these operations and is therefore inefficient.
Recusively coding the insert/remove methods to handle these situations is a great learning experience.
5. (R) The level order print (PRINT command) outputs the value of each node, the size of the tree rooted at that node, and the value of the node's parent in that order, inside parenthesis, separated by commas. (node value, tree size, parent value). Since the root has no parent, print NULL for the root's parent value. For readability, separate the levels with a blank line and print no more than 6 node/size/parent values per line. If a level requires multiple lines, use consecutive lines (without a blank line between the ...
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
Write a Java Class to Implement a Generic Linked List
Your list must be implemented as a singly-linked list of generic nodes, where each Node object
has two instance variables: an object of the “type variable” class, and a pointer to the next node
on the list.
Your class will contain separate methods to handle each of the operations read from a data file
(see II., below)
Your class will also override toString() to return the objects on the list in the order in which they
occur.
Write a Test Class for Your LinkedList Class
Your main method will read list operation instructions from a data file, until end-of-file and call
the appropriate LinkedList method to execute each one.
After each operation is executed, print out the operation and the updated list.
The data file to be used is on the class web site and the operations are:
APPEND X - Append object X to the end of the list
ADD N X - Insert object X as the new Nth element in the list, increasing the size of the list by 1
E.g. Suppose the list is:
head -> 1 -> 2 -> 3 -> 4->null
After ADD 3 7 it would be:
head -> 1 -> 2 -> 7 -> 3 -> 4->null
DELETE N – Remove the Nth object from the list
SWAP M N - Interchange the positions of the Mth and Nth
objects on the list
For credit, the two nodes must actually \"trade places\" in the list, and not merely swap their data
values
REVERSE - Reverse the order of the objects on the list
This must be done by reversing the order of the nodes themselves, rather than by swapping the
data stored
To get credit for your reverse() method, it must use either one of these 2 algorithms:
For each node on the list except the current “head”
node, delete the node and insert it as the new head
Use your swap() method
6. CLEAR – Clear the list (make it empty)
No credit will be given for programs that use any additional data structures – either from the Java
API or programmer defined -, other than your own LinkedList class
txt file:
Solution
//Java Program to Implement Singly Linked List
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/* Class Node */
class Nodes
{
protected Object data;
protected Nodes next;
/* Constructor */
public Nodes()
{
next = null;
data = null;
}
/* Constructor */
public Nodes(Object d,Nodes n)
{
data = d;
next = n;
}
/* Function to set link to next Node */
public void setLink(Nodes n)
{
next = n;
}
/* Function to set data to current Node */
public void setData(Object d)
{
data = d;
}
/* Function to get link to next node */
public Nodes getLink()
{
return next;
}
/* Function to get data from current Node */
public Object getData()
{
return data;
}
}
/* Class linkedList */
class linkList
{
protected Nodes start;
protected Nodes end ;
public int size ;
/* Constructor */
public linkList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isEmpty()
{
return start == null;
}
/* Function to get size of list */
public int getSize()
{
return .
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
hi i have to write a java program involving link lists. i have a problem with the nodes, as it is
posting errors with the nodes.
please help me with this problem. thank you.
public class LinkLists {
/* only need to store a single pointer to the node at the head
* of the list.
* The pointer is null if the list is empty.
* Also record the size of the list.
*/
protected Node head;
/* invariant: size is the number of nodes in the list pointed to by head */
protected int size;
/* no-arguments default constructor creates an empty list */
public LinkLists() {
head = null; // start with an empty list
size = 0;
}
/* accessor method */
public int size() {
return size;
}
/* value to add to the end of the list
*/
public void add(T value) {
head = addAtEnd(head, value);
size++;
}
/* node of the list to which the value should be added
* value to add to the end of the list
*/
private Node addAtEnd(Node node, T value) {
if (node == null) { // special case
return new Node(value, null);
} else if (node.getNext() == null) { // other special case
node.setNext(new Node(value, null));
} else {
addAtEnd(node.getNext(), value);
}
return node;
}
/* iterative implementation of the same method
* value to add to the end of the list
*/
public void add2(T value) {
if (head == null) {
head = new Node(value, null);
} else {
Node node = head; // guaranteed not to be null initially
while (node.getNext() != null) {
node = node.getNext(); // guaranteed not to be null here
}
// now, node.getNext() is guaranteed to be null
// similar to the second special case in addAtEnd
node.setNext(new Node(value, null));
}
size++;
}
public void remove(int position) throws BadItemCountException {
if ((position < 1) || (position > size)) {
throw new
BadItemCountException(\"invalid position \" + position +
\", only 1..\" + size + \" available\");
}
if (position == 1) {
head = head.getNext();
} else {
Node node = head;
for (int i = 2; i < position; i++) {
node = node.getNext();
}
node.setNext(node.getNext().getNext());
}
size--; // one less item
}
public String toString() {
return toString(head);
}
private String toString(Node node) {
if (node == null) {
return \"\";
} else {
return node.getValue() + \"\ \" + toString(node.getNext());
}
}
public static void main(String[] args) {
/* create two empty lists, make sure they print out correctly */
LinkLists list1 = new LinkLists();
LinkLists list2 = new LinkLists();
System.out.println(\"list1 = \'\" + list1 + \"\', list2 = \'\" + list2 + \"\'\");
System.out.println(\"list1.size() = \" + list1.size() +
\", list2.size() = \" + list2.size());
/* insert some items, keep checking */
list1.add(\"hello\");
list1.add(\"world\");
list2.add(\"foo\");
list2.add(\"bar\");
list2.add(\"baz\");
System.out.println(\"list1 = \'\" + list1 + \"\', list2 = \'\" + list2 + \"\'\");
System.out.println(\"list1.size() = \" + list1.size() +
\", list2.size() = \" + list2.size());
/* remove an item at an invalid position */
boolean caught = false;
try {
list2.remove(4);
} catch .
Once you have all the structures working as intended- it is time to co.docxfarrahkur54
Once you have all the structures working as intended, it is time to compare the
performances of the 2. Use runBenchmark() to start.
a. First, generate an increasing number (N) of random integers (1000, 5000, 10000,
50000, 75000, 100000, 500000 or as far as your computing power will let you)
i. Time and print how long it takes to insert the random integers into an initially
empty BST. Do not print the tree.
You can get a random list using the java class Random, located in
java.util.Random. To test the speed of the insertion algorithm, you should use
the System.currentTimeMillis() method, which returns a long that contains the
current time (in milliseconds). Call System.currentTimeMillis() before and after
the algorithm runs and subtract the two times. (Instant.now() is an alternative
way of recording the time.)
ii. Time and print how long it takes to insert the same random integers into an
initially empty AVL tree. Do not print the tree.
iii. If T(N) is the time function, how does the growth of TBST(N) compare with the
growth of TAVL(N)?
Plot a simple graph to of time against N for the two types of BSTs to visualize
your results.
b. Second, generate a list of k random integers. k is also some large value.
i. Time how long it takes to search your various N-node BSTs for all k random
integers. It does not matter whether the search succeeds.
ii. Time how long it takes to search your N-node AVL trees for the same k random
integers.
iii. Compare the growth rates of these two search time-functions with a graph the
same way you did in part a.
public class BinarySearchTree<AnyType extends Comparable<? super AnyType>> {
protected BinaryNode<AnyType> root;
public BinarySearchTree() {
root = null;
}
/**
* Insert into the tree; duplicates are ignored.
*
* @param x the item to insert.
* @param root
* @return
*/
protected BinaryNode<AnyType> insert(AnyType x, BinaryNode<AnyType> root) {
// If the root is null, we've reached an empty leaf node, so we create a new node
// with the value x and return it
if (root == null) {
return new BinaryNode<>(x, null, null);
}
// Compare the value of x to the value stored in the root node
int compareResult = x.compareTo(root.element);
// If x is less than the value stored in the root node, we insert it into the left subtree
if (compareResult < 0) {
root.left = insert(x, root.left);
}
// If x is greater than the value stored in the root node, we insert it into the right subtree
else if (compareResult > 0) {
root.right = insert(x, root.right);
}
// If x is equal to the value stored in the root node, we ignore it since the tree does not allow duplicates
return root;
}
/**
* Counts the number of leaf nodes in this tree.
*
* @param t The root of the tree.
* @return
*/
private int countLeafNodes(BinaryNode<AnyType> root) {
// If the root is null, it means the tree is empty, so we return 0
if (root == null) {
return 0;
}
// If the root has no children, it means it is a leaf node, so we return 1
if (root.left == .
4. The size of instructions can be fixed or variable. What are advant.pdfmumnesh
4. The size of instructions can be fixed or variable. What are advantage and disadvantage of
fixed compared to variable? point) eft 2 20 0 C-4131-28 Add suction 131-26 nvaction 125-2 PC
egister daiess mancion 120-16 date 1 regnter 2 nstructien 31-00 eg stcrs Read U ALLu dela tlata
dvts 02 rstend In the above figure (single-cycle implementation), current instruction is SW S1,
4(S2) (SW: Store Word; current addrss for this instruction is 100 in decimal; S1 and $2 are
initially 8). For redundancy, you should write \"X\" instead of 0 or . You should write the reason
for cach question as well. 5. What is the value of RegDst? (1 point) 6. What is the value of
RegWrite? (I point) 7. What is the value after sign-extension? 1 point) 8. What is the value of
MemRead? (1 point) 9. What is the value of MemtoReg? (1 point) In the above figure, current
instruction is ADDI $1. S2, #-1(which is minus l) (ADDI is ADD Immediate; current address for
this instruction s 100 in decimal and S2 are initially1). For redundancy, you should write “X\',
instead of 0 or 1 . You should write the reason for each question as well. 10. What is the value
(immediate value) of instruction [15-0)? Write the value in 6-bit binary (1 point) 11. What is the
value after sign extension? Write the value in 32-bit binary. (I point) 12. What is the value of
Reg Write? (1 point) 13. What is the value of MemtoReg? (1 point) 2/4
Solution
import java.util.AbstractSet; import java.util.Arrays; import java.util.Iterator; import
java.util.NoSuchElementException; /** * Implementation of an abstract set using an array-
based binary tree. This is * used to help teach binary tree\'s and will have more details explained
in * future lectures. * * @author William J. Collins * @author Matthew Hertz * @param
Data type (which must be Comparable) of the elements in this tree. */ public class
ArrayBinaryTree> extends AbstractSet { /** Entry in the data store where the root node can be
found. */ private static final int ROOT = 0; /** Array used to store the nodes which consist of
this binary tree. */ protected Node[] store; /** Number of elements within the tree. */
protected int size; /** * Initializes this ArrayBinaryTree object to be empty. This creates the
array * in which items will be stored. */ @SuppressWarnings(\"unchecked\") public
ArrayBinaryTree() { store = new Node[63]; size = 0; } /** * Initializes this
ArrayBinaryTree object to contain a shallow copy of a * specified ArrayBinaryTree object.
The worstTime(n) is O(n), where n is the * number of elements in the specified
ArrayBinaryTree object. * * @param otherTree The tree which will be copied to create our
new tree, */ @SuppressWarnings(\"unchecked\") public ArrayBinaryTree(ArrayBinaryTree
otherTree) { store = (Node[]) Arrays.copyOf(otherTree.store, otherTree.store.length); size =
otherTree.size; } public int countLeaves() { } /** * Returns the size of this
ArrayBinaryTree object. * * @return the size of this ArrayBinaryTree object. */
@Overrid.
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
How do I fix it in LinkedList.java?
this is what i did
LabProgram.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 remov.
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
Here is the editable code:
Solution
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
public int size() { return size; }
public boolean isEmpty() { return size == 0; }
public void addFirst(E element) {
Node tmp = new Node(element, head, null);
if(head != null ) {head.prev = tmp;}
head = tmp;
if(tail == null) { tail = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* adds element at the end of the linked list
* @param element
*/
public void addLast(E element) {
Node tmp = new Node(element, null, tail);
if(tail != null) {tail.next = tmp;}
tail = tmp;
if(head == null) { head = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
public void iterateForward(){
System.out.println(\"iterating forward..\");
Node tmp = head;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.next;
}
}
/**
* this method walks backward through the linked list
*/
public void iterateBackward(){
System.out.println(\"iterating backword..\");
Node tmp = tail;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.prev;
}
}
public E removeFirst() {
if (size == 0) throw new NoSuchElementException();
Node tmp = head;
head = head.next;
head.prev = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public E removeLast() {
if (size == 0) throw new NoSuchElementException();
Node tmp = tail;
tail = tail.prev;
tail.next = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public static void main(String a[]){
DoublyLinkedListImpl dll = new DoublyLinkedListImpl();
dll.addFirst(10);
dll.addFirst(34);
dll.addLast(56);
dll.addLast(364);
dll.iterateForward();
dll.removeFirst();
dll.removeLast();
dll.iterateBackward();
}
}
import java.util.Scanner;
/* Class Node */
class Node
{
protected int data;
protected Node next, prev;
/* Constructor */
public Node()
{
next = null;
prev = null;
data = 0;
}
/* Constructor */
public Node(int d, Node n, Node p)
{
data = d;
next = n;
prev = p;
}
/* Function to set link to next node */
public void setLinkNext(Node n)
{
next = n;
}
/* Function to set link to previous node */
public void setLinkPrev(Node p)
{
prev = p;
}
/* Funtion to get link to next node */
public Node getLinkNext()
{
return next;
}
/* Function to get link to previous node */
public Node getLinkPrev()
{
return prev;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Class linkedList */
class linkedList
{
protected Node start;
protected Node end ;
public int size;
/* Constructor */
public linkedList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isE.
Please write in C++ and should be able to compile and debug.Thank yo.pdfajaycosmeticslg
Please write in C++ and should be able to compile and debug.Thank you
Create a class called BinaryTreeDeque. This binary tree implements all of the functionality of
the BinaryTree class, but instead of storing its values in a tree structure, the element values are
stored in a deque, using pointers to maintain the relationship between the binary tree and its node
values. Additionally: deque * getValues() - returns a copy of the deque the current array of
values (which should be in insertion order).
Solution
Following are steps to insert a new node in Complete Binary Tree.
1. If the tree is empty, initialize the root with new node.
2. Else, get the front node of the queue.
…….If the left child of this front node doesn’t exist, set the left child as the new node.
…….else if the right child of this front node doesn’t exist, set the right child as the new node.
3. If the front node has both the left child and right child, Dequeue() it.
4. Enqueue() the new node.
Code :-
-------------------------
binarytreedequeue.h
#ifndef BINARYTREEDEQUE_H
#define BINARYTREEDEQUE_H
// Program for linked implementation of complete binary tree
#include
#include
// For Queue Size
#define SIZE 50
// A tree node
struct node
{
int data;
struct node *right,*left;
};
// A queue node
struct Queue
{
int front, rear;
int size;
struct node* *array;
};
class BinaryTreeDeque
{
public:
BinaryTreeDeque();
struct node* newNode(int data);
struct Queue* createQueue(int size);
int isEmpty(struct Queue* queue);
int isFull(struct Queue* queue);
int hasOnlyOneItem(struct Queue* queue);
void Enqueue(struct node *root, struct Queue* queue);
struct node* Dequeue(struct Queue* queue);
struct node* getFront(struct Queue* queue);
int hasBothChild(struct node* temp);
void insert(struct node **root, int data, struct Queue* queue);
void display(struct Queue* queue);
node * getValues(struct Queue* queue);
};
#endif // BINARYTREEDEQUE_H
binarydequeue.cpp
---------------------------------------
#include \"binarytreedeque.h\"
BinaryTreeDeque::BinaryTreeDeque()
{
}
// A utility function to create a new tree node
struct node* BinaryTreeDeque::newNode(int data)
{
struct node* temp = (struct node*) malloc(sizeof( struct node ));
temp->data = data;
temp->left = temp->right = NULL;
return temp;
}
// A utility function to create a new Queue
struct Queue* BinaryTreeDeque::createQueue(int size)
{
struct Queue* queue = (struct Queue*) malloc(sizeof( struct Queue ));
queue->front = queue->rear = -1;
queue->size = size;
queue->array = (struct node**) malloc(queue->size * sizeof( struct node* ));
int i;
for (i = 0; i < size; ++i)
queue->array[i] = NULL;
return queue;
}
// Standard Queue Functions
int BinaryTreeDeque::isEmpty(struct Queue* queue)
{
return queue->front == -1;
}
int BinaryTreeDeque::isFull(struct Queue* queue)
{ return queue->rear == queue->size - 1; }
int BinaryTreeDeque::hasOnlyOneItem(struct Queue* queue)
{ return queue->front == queue->rear; }
void BinaryTreeDeque::Enqueue(struct node *root, s.
Need Help with this Java Assignment. Program should be done in JAVA .pdfarchiesgallery
Need Help with this Java Assignment. Program should be done in JAVA please
Complete required scripts based on eclipse and troubleshoot the scripts until the tasks are done.
1. Implement a binary search tree (write the code for it), for a height of 2 or higher. Please show
the output if you can Thank you in advance!
Solution
I have compiled this code and checked for errors, worked fine.
Also after the code I have pasted the Output transcript to show what User Inputs I gave and what
all outputs I got.
// Java Program to Implement Binary Tree
import java.util.Scanner;
/* Define Class BinaryTreeNode */
class BinaryTreeNode
{
BinaryTreeNode left, right;
int data;
/* Constructor */
public BinaryTreeNode()
{
left = null;
right = null;
data = 0;
}
/* Constructor */
public BinaryTreeNode(int n)
{
left = null;
right = null;
data = n;
}
/* Function to set left node */
public void setLeft(BinaryTreeNode n)
{
left = n;
}
/* Function to set right node */
public void setRight(BinaryTreeNode n)
{
right = n;
}
/* Function to get left node */
public BinaryTreeNode getLeft()
{
return left;
}
/* Function to get right node */
public BinaryTreeNode getRight()
{
return right;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Define anothe Class Operations to perform required operationns on Binary Tree*/
class Operations
{
private BinaryTreeNode root;
/* Constructor */
public Operations()
{
root = null;
}
/* Function to check if tree is empty */
public boolean isEmpty()
{
return root == null;
}
/* Functions to insert data */
public void insert(int data)
{
root = insert(root, data);
}
/* Function to insert data recursively */
private BinaryTreeNode insert(BinaryTreeNode node, int data)
{
if (node == null)
node = new BinaryTreeNode(data);
else
{
if (node.getRight() == null)
node.right = insert(node.right, data);
else
node.left = insert(node.left, data);
}
return node;
}
/* Function to count number of nodes */
public int countNodes()
{
return countNodes(root);
}
/* Function to count number of nodes recursively */
private int countNodes(BinaryTreeNode r)
{
if (r == null)
return 0;
else
{
int l = 1;
l += countNodes(r.getLeft());
l += countNodes(r.getRight());
return l;
}
}
/* Function to search for an element */
public boolean search(int val)
{
return search(root, val);
}
/* Function to search for an element recursively */
private boolean search(BinaryTreeNode r, int val)
{
if (r.getData() == val)
return true;
if (r.getLeft() != null)
if (search(r.getLeft(), val))
return true;
if (r.getRight() != null)
if (search(r.getRight(), val))
return true;
return false;
}
/* Function for inorder traversal */
public void inorder()
{
inorder(root);
}
private void inorder(BinaryTreeNode r)
{
if (r != null)
{
inorder(r.getLeft());
System.out.print(r.getData() +\" \");
inorder(r.getRight());
}
}
/* Function for preorder traversal */
public void preorder()
{
preorder(root);
}
priva.
File LinkedList.java Defines a doubly-l.pdfConint29
File: LinkedList.java
/**
* Defines a doubly-linked list class
*/
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() {
}
/**
* 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 {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* 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 null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @pos.
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
package singlylinkedlist;
public class Node {
public String value;
public Node next;
public Node(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
SingleyLinkedList.java :
package singlylinkedlist;
import java.io.*;
import java.util.*;
/**
* Defines the interface for a singly-linked list.
*
*/
public interface SinglyLinkedList {
/**
* @return Reference to the first node. If the list is empty, this method
* returns null.
*/
public Node getFirst();
/**
* @return Reference to the last node . If the list is empty, this method
* returns null.
*/
public Node getLast();
/**
* @return Number of nodes in the list
*/
public int size();
/**
* @return true if the list has no nodes; false otherwise
*/
public boolean isEmpty();
/**
* Removes all nodes in the list.
*/
public void clear();
/**
* Inserts a new node with the given value after cursor.
*
* @param cursor
* The node to insert after. Set this to null to insert value as
the
* new first Node.
* @param value
* The value to insert
* @return a reference to the newly inserted Node
*/
public Node insert(Node cursor, String value);
/**
* Inserts a new node with the given value at the "end" of the list.
*
* @param value
* @return a reference to the newly inserted Node
*/
public Node append(String value);
/**
* Removes the node after the specified Node (cursor) from the list.
*
* @param cursor
* A reference to the Node to remove.
*/
public void removeAfter(Node cursor);
/**
* Returns a reference to the first Node containing the key, starting from
the
* given Node.
*
* @param start
* @param key
* @return a reference to the first Node containing the key
*/
public Node find(Node start, String key);
/**
* Prints the values of all the items in a list
*/
public void printWholeList();
}
SinglyLinkedTester.java:
package sbccunittest;
import static java.lang.Math.*;
import static java.lang.System.*;
import static org.apache.commons.lang3.StringUtils.*;
import static org.junit.Assert.*;
import static sbcc.Core.*;
import java.io.*;
import java.lang.reflect.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
import org.apache.commons.lang3.*;
import org.junit.*;
import org.w3c.dom.ranges.*;
import sbcc.*;
import singlylinkedlist.*;
/**
* 09/16/2021
*
* @author sstrenn
*
*/
public class SinglyLinkedListTester {
public static String newline = System.getProperty("line.separator");
public static int totalScore = 0;
public static int extraCredit = 0;
public static boolean isZeroScore = false;
public static String scorePreamble = "";
@BeforeClass
public static void beforeTesting() {
totalScore = 0;
extraCredit = 0;
}
@AfterClass
public static void afterTesting() {
if (isZeroScore) {
totalScore = 0;
extraCredit = 0;
}
println(scorePreamble + "Estimated score (w/o late penalties, etc.) is:
" + totalScore + " out of 25.");
// If the project follows the naming convention, save the results in a
folder on
// the desktop. (Alex Kohanim)
try {
String directory =
substri.
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdffathimalinks
Write the following using java
Given a class ‘Node’ and ‘NodeList’, that contains the below information diagram.
-id: int
-name: String
-next: Node
+Node(id: int, name: String)
+setId(id: int): void
+getId(): int
+setName(name: String) : void
+getName(): String
+setNext(node: Node): void
+getNext(): Node
NodeList
-size: int
-root: Node
+add(node: Node): void
+size(): int
+findNode(node: Node): boolean
Implement add(Node), findNode(Node) and size methods in the NodeList class which is
provided to you. The methods should work as:
Using the following main method:
public static void main(String[] args)
{
NodeList list = new NodeList();
Node node = new Node(1, \"Book\");
Node node2 = new Node(2, \"Lappy\");
list.add(node);
list.add(node2);
System.out.println(\"Length : \"+list.size());
Node node3 = new Node(3, \"Glass\");
Node node4 = new Node(4, \"Pen\");
list.add(node3);
System.out.println(\"Length : \"+list.size());
if(list.findNode(node3)) System.out.println(\"Node found: \"+ node3.getName());
else
System.out.println(\"Node not found: \"+ node3.getName());
if(list.findNode(node4)) System.out.println(\"Node found: \"+ node4.getName());
else
System.out.println(\"Node not found: \"+ node4.getName());
}
Then it should return the following output:
Length : 2
Length : 3
Node found: Glass
Node not found: Pen
The given Node class is:
public class Node
{
private int id = 0;
private String name = \"\";
private Node next;
public Node(int id, String name)
{
this.id = id;
this.name = name;
this.next = null;
}
public Node getNext()
{
return next;
}
public void setNext(Node node)
{
this.next = node
}
public int getId()
{
return id;
{
public void setId(int id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String toString()
{
return \"ID : \"+this.id+\" Name : \"+this.name;
}
}
The given NodeList class is:
public class NodeList
{
private int size = 0;
private Node root = null;
/*
* It has to take a new Node and add that to the next address of previous Node.
* If the list is empty, assign it as the \"root\"
* @Param - Node
*/
public void add(Node node)
{
// Implement this method!!!
}
/*
* It has to return the size of the NodeList
*
* @return size
*/
public int size()
{
// Implement this method!!!
}
/*
* It has to take a Node and checks if the node is in the list.
* If it finds the node, it returns true, otherwise false
*
* @param - Node
* @return boolean true/false
*/
public boolean findNode(Node node)
{
// Implement this method!!!
}
}Node
-id: int
-name: String
-next: Node
+Node(id: int, name: String)
+setId(id: int): void
+getId(): int
+setName(name: String) : void
+getName(): String
+setNext(node: Node): void
+getNext(): Node
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
############ Node.java #############
public class Node
{
private int id = 0;
private String name = \"\";
private Node next;
public Node(int id, String name)
{
this.id = id;
this..
Similar to Help please!!(Include your modified DList.java source code file in.pdf (20)
How does an open source operating system like Linux® affect Internet.pdfjyothimuppasani1
How does an open source operating system like Linux® affect Internet security and safety?
Solution
Since open source operating system\'s code is available to all,it\'s provides an easy access to
hackers and potential misusers which affects safety of such systems.
The non stable nature of Open source operating system also can be considered an important
factor that affects the Security.This is because Developers all over the globe modify the code and
thus the code is not stable and it becomes vulnerable to security threats.
Even if patches are introduced from time to time,mostly after an attack or so but due to large
flavours or distributions of open source software, some flavours are left without patches that
makes them vulnerable to attacks.
Also,The administration of open source operating system Servers also plays an important factor
in Internet Security. Since it is known that for example,Linux Server administration is more
difficult and when multiple ports are open it is sometimes not possible to handle an attack or
security threat immediately.
But then as it is said that every coin has two sides, Sometimes it is considered that Open Source
Systems like Linux are more secure because of the following reasons :.
how can I replace the Newsfeed text with a custom on in SharePoi.pdfjyothimuppasani1
how can I replace the \"Newsfeed\" text with a custom on in SharePoint 365.
(Newsfeed Webpart)
Solution
First of all there are some differences between sharepoint and office 365. SharePoint has 4
versions still in active use : SharePoint 2007,2010,2016 and office 365. Office 365 released in
2011 With SharePoint2010 interface. Office 365 hav a various exclusive features like NextGen
Portals (Out of the box “ready to go” portals), Delve (A technology based on Office Graph that
presents “relevant information” to you based on your actions and interactions with colleague
files), Sway (A presentation web par that allows users to combine text, images and videos locally
and from the wider internet to create a usable website.), Yammer Integration (Yammer is the
enterprise social network that\'s being gradually rolled into all Office 365 features.) anf Office
365 Groups.
A custom CSS included in SharePoint master page in order to customize Newsfeed Web Part.
the code is:
.ms-microfeed-siteFeedTitleArea
{
background-color: silver;
padding-left: 20px;
text-transform:uppercase;
padding-bottom: 3px;
padding-top: 2px;
margin-bottom: 5px;
}
.ms-microfeed-siteFeedMicroBlogPart
{
margin-bottom: 2px;
}
.ms-microfeed-siteFeedTitleLabel
{
color: red !important;
}
.ms-microfeed-threadsDiv
{
height: 250px;
overflow-y: auto;
overflow-x: hidden;
}
.ms-microfeed-thread
{
max-width: 435px;
margin-bottom: 10px;
}
.ms-microfeed-replyArea
{
max-width: 375px;
min-width: 300px;
}
.ms-microfeed-attachmentButton
{
padding-top: 2px;
padding-bottom: 2px;
display: block;
}
.ms-microfeed-postButton
{
padding-top: 2px;
padding-bottom: 2px;
}
.ms-microfeed-postButtonSpan
{
margin-top: 2px;
}
.ms-microfeed-postBox
{
height: 20px;
}
Apart from this we can also hide controls, for this first we need to activate Site Feed feature, to
do this go to site settings->Manage Site Features and activate it
script for hide controls
I used the following CSS classes and its worked.
.ms-microfeed-cancelButton{
background-color: #fcfcfc !important;
border: 1px solid #d4d4d4 !important;
-moz-border-radius: 10px !important;
-webkit-border-radius: 10px !important;
border-radius: 10px !important;
color: #00a6d9 !important;
height: 22px !important;
padding-top: 3px !important;
width: 78px !important;
font-family: Arial !important;
font-size: 11px!important;
font-weight: normal !important;
}
.ms-microfeed-siteFeedTitleArea
{
background-color: silver;
padding-left: 20px;
text-transform:uppercase;
padding-bottom: 3px;
padding-top: 2px;
margin-bottom: 5px;
}
.ms-microfeed-siteFeedMicroBlogPart
{
margin-bottom: 2px;
}
.ms-microfeed-siteFeedTitleLabel
{
color: red !important;
}
.ms-microfeed-threadsDiv
{
height: 250px;
overflow-y: auto;
overflow-x: hidden;
}
.ms-microfeed-thread
{
max-width: 435px;
margin-bottom: 10px;
}
.ms-microfeed-replyArea
{
max-width: 375px;
min-width: 300px;
}
.ms-microfeed-attachmentButton
{
padding-top: 2px;
padding-bottom: 2px;
padding-bottom: 2px;
display: block;
}
.ms-microfeed-pos.
Hello!This is Java assignment applet.Can someone help me writing.pdfjyothimuppasani1
Hello!
This is Java assignment applet.
Can someone help me writing a code how to exit the game when I press no in question( would
you like to play again?). Also if no one wins or draws i would like to pop up the question ( would
you like to play again?). I have the code below i would like someone to add it
Thanks in advance!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class TicTacToe extends Applet implements ActionListener{
// Array to store buttons
JButton button[][] = new JButton[3][3];
boolean isNewGame =false;
// To switch player either X or O
boolean isZero = true; //first turn is always 0
// Setup size
// Set layout to grid
// Create buttons through loop
// Add buttons to layout
// Add listener
public void init(){
setSize(500, 500);
setLayout(new GridLayout(3,3));
// if it is not a new game
if(isNewGame==false) {
// Adding buttons to layout
//initialize the Grid and add ActionListener to each Button
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
// init jButton
button[i][j] = new JButton(\"\");
// Setup Font and Size here
button[i][j].setFont(new Font(\"Lucida Grande\", Font.PLAIN, 28));
// Add is a method from applet to add buttons in layout
add(button[i][j]);
// Listener
button[i][j].addActionListener(this);
}
}
}
else {
// If we need to restart the game, then we only set text to empty
// Back to black color
// add listener
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
button[i][j].setText(\"\");
button[i][j].setForeground(Color.BLACK);
button[i][j].removeActionListener(this);
button[i][j].addActionListener(this);
}
}
}
}
// Go all the buttons in arrsy
// Check the event with button in array
// if player O is true, set button text O. Otherwise. X
// Remove Listerner. Why? only once you can click
// Change player by isZero
// Check for winner
public void actionPerformed(ActionEvent event){
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++){
if((event.getSource() == button[i][j])){
if(isZero){
button[i][j].setText(\"O\");
}
else{
button[i][j].setText(\"X\");
}
button[i][j].removeActionListener(this); //you cannot click on one tile more than
once
isZero = !isZero;
checkForWinners(); //check if any winner after each move
}
}
}
public void checkForWinners(){
//3 horizontal lines
for(int i = 0; i < 3; i++){
if(button[i][0].getText().equals(button[i][1].getText())
&& button[i][1].getText().equals(button[i][2].getText())
&& !button[i][0].getText().equals(\"\")){
String player = button[i][0].getText();
button[i][0].setForeground(Color.RED);
button[i][1].setForeground(Color.RED);
button[i][2].setForeground(Color.RED);
int reply =JOptionPane.showConfirmDialog(null, player + \" wins!\"+\"\ Would like
to play again?\",\"Game over\",JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
isNewGame = true;
init();
return;
}
else {
System.exit(0);
return;
}
}
}
//3 vertical lines
for(int i = 0; i < 3; i++){
if(button[0][i].getText().equals(button[1][i].getText())
&& .
For each of the following reseach questions identify the observation.pdfjyothimuppasani1
For each of the following reseach questions identify the observational units and variable (s)
P. 1.2Subjects listened to ten second of the Jackson 5 \'s song \"ABC\" and then were how long
they thought the song snippet lasted . Do people tend to overestimate the song length?
Solution
variable is song length. In other words the time subjects think they listened to song.
unit is seconds.
Find an Eulerian trail in the following graph. Be sure to indicate th.pdfjyothimuppasani1
Find an Eulerian trail in the following graph. Be sure to indicate the order in which the edges are
visited.
Solution
Eulerian path/ trail:
A path is called as Eulerian path if every edge of the graph G appears exactly ince in the path.
NOTE::
A graph possesses an Eulerian trail if and only if it is connected and has either zero and 2
vertices of odd degrees
ANSWER:
order -> h,d,c,b,f,e,b,a,e,i,j,f,g,k,l,h,g,c,d.
File encryption. [32] Write a program which accepts a filename as a .pdfjyothimuppasani1
File encryption. [32] Write a program which accepts a filename as a command-line argument [-
32]. It should then ask for a password via stdin (but it should not visible when entered; use
getpass for this) [4]. The program should encrypt the file using a block-cipher algorithm (see
encryption.rst for details) [12] if it was not already encrypted by the program, and rename it with
a .enc extension. If it was already encrypted, it should decrypt the file and remove the .enc
extension [12]. Under no circumstance should the program multiply encrypt the file [4]. Call the
program encrypt.cpp. here is encrypt.rst Suppose I have an input file to encrypt: .. raw: The only
true wisdom is in knowing you know nothing. (A quote by Socrates.) What I can do then is ask
the user for a password. Suppose the user enters kitties. Then what I may do is pre-pend the
password to an output file, and add kitties in rounds to the file: .. raw: kittiesThe only true
wisdom is in knowing you know nothing. + kittieskittieskittieskittieskittieskittieskittieskittieskit -
---------------------------------------------------------- =
fhdkalhfioepwahfkdsanklvcxznkjvpwipqnkxlkdlajsflkjkljkljlkd When I add the characters in the
string kitties, I get what appears to be jumbled garbage. Without the password, it is hard to
decrypt the file. To decrypt the file, I ask the user for the password. Suppose they enter bubbles
(the wrong password). .. raw: fhdkalhfioepwah... - bubbles ------------------ = ueiaqnv I see that
by subtracting bubbles off the encrypted text, I do not get the string bubbles back, so bubbles is
not the password. If the user enters kitties (the correct password): .. raw: fhdkalhfioepwah... -
kitties ------------------ = kitties Then I see that what I get back is kitties, and since it matches the
user password entered, I may proceed to decrypt the rest of the file simply by subtracting kitties
off it in rounds. .. raw: = fhdkalhfioepwahfkdsanklvcxznkjvpwipqnkxlkdlajsflkjkljkljlkd -
kittieskittieskittieskittieskittieskittieskittieskittieskit ------------------------------------------------------
----- kittiesThe only true wisdom is in knowing you know nothing. Thus I obtain the original
message. Notice the user-supplied password itself is a necessary element of the decryption. This
type of algorithm is called a block cipher algorithm.
Solution
// Encrypting_a_File.cpp : Defines the entry point for the console
// application.
//
#include
#include
#include
#include
#include
// Link with the Advapi32.lib file.
#pragma comment (lib, \"advapi32\")
#define KEYLENGTH 0x00800000
#define ENCRYPT_ALGORITHM CALG_RC4
#define ENCRYPT_BLOCK_SIZE 8
bool MyEncryptFile(
LPTSTR szSource,
LPTSTR szDestination,
LPTSTR szPassword);
void MyHandleError(
LPTSTR psz,
int nErrorNumber);
int _tmain(int argc, _TCHAR* argv[])
{
if(argc < 3)
{
_tprintf(TEXT(\"Usage: \")
TEXT(\" | \ \"));
_tprintf(TEXT(\" is optional.\ \"));
_tprintf(TEXT(\"Press any key to exit.\"));
_gettch();
return 1;
}
LPTS.
Explain the relevance that medical standards of practice have to one.pdfjyothimuppasani1
Explain the relevance that medical standards of practice have to one as a practioner?
Solution
\'Providing care\' incorporates, however isn\'t restricted to any care,
treatment, counsel, administration or merchandise gave in regard
of the physical or emotional well-being of a man, regardless of whether
compensated or genius bono.
\'Practice\' implies any part, regardless of whether compensated or not,
in which the individual uses their aptitudes and learning
as a specialist in their controlled wellbeing calling. For
the motivations behind this Code, rehearse isn\'t limited to
the arrangement of direct clinical care. It additionally incorporates utilizing
proficient learning in a direct nonclinical relationship
with patients or customers, working in administration,
organization, instruction, look into, warning, administrative or
arrangement improvement parts and whatever other parts that effect
on sheltered, powerful conveyance of wellbeing administrations in the wellbeing
calling.
Keeping up and creating learning, aptitudes and
proficient conduct are center parts of good practice.
This requires self-reflection and support in pertinent
proficient advancement, rehearse change and
execution evaluation procedures to persistently create
proficient capacities. These exercises must proceed
through a specialist\'s working life as science and
innovation create and society changes.
giving specialists who are patients or customers with
a similar nature of care gave to different patients or
customers
b). informing the sheets if treating another enrolled
specialist who has set patients or customers in danger
of significant mischief while rehearsing their calling
since they have an impedance (allude to the
board\'s rules on compulsory detailing) this is a
proficient and also a statutory obligation under
the National Law
At the point when specialists are engaged with look into that includes
patients or customers, great practice incorporates:
a). regarding the privilege of patients or customers to pull back
from an investigation without partiality to their treatment
b). guaranteeing that a choice by patients or customers not to
take an interest does not bargain the specialist
tolerant/customer relationship or the care of the patient or
customer..
Find the mission and values statements for four different hospita.pdfjyothimuppasani1
Find the mission and values statements for four different hospital types. Do their missions and
values reconcile with your expectations for the type of organization? Look at a religious based
organization. Does their mission and values reflect their religious teachings and mission? Now
examine a for-profit hospital. Does their mission and values include the need to increase their
owners\' value and maximizing their earning? Why do you think the missions and values are
structured as they are? 1. The missions and values are structured as they are to meet the desires
of the stakeholders. The specifics of this question must be left to the particulars of the
instructional environment.
Solution
We will describe mission and value statements of four hospitals given below:-
a) Seattle Children\'s Hospital
Mission statement:-
We provide hope, care and cures to help every child live the healthiest and most fulfilling life
possible.
Value statement:-
Compassion
Empathy for patients, their families and staff is ingrained in our history and inspires our future.
We do more than treat the child; we practice family-centered care as the cornerstone of
compassion.
Excellence
Our promise to treat, prevent and cure pediatric disease is an enormous responsibility. We follow
the highest standards of quality and safety and expect accountability from each other.
Integrity
At all times, we approach our work with openness, transparency, decency and humility. It is our
responsibility to use resources wisely to sustain Seattle Children’s for generations to come.
Collaboration
We work in partnership with patients, their families, staff, providers, volunteers and donors. This
spirit of respectful cooperation extends beyond our walls to our business partners and the
community.
Equity
We embrace and find strength in the diversity of our patients, their families, staff and
community. We believe all children deserve exceptional care, the best outcomes, respect and a
safe environment.
Innovation
We aspire to be an innovative leader in pediatric healthcare, research and philanthropy. We
continually seek new and better solutions. Because innovation springs from knowledge, we
foster learning in all disciplines.
b) Rochester Regional Health
Mission statement:-
To enhance lives and preserve health by enabling access to a comprehensive, fully integrated
network of the highest quality and most affordable care, delivered with kindness, integrity and
respect.
Value Statement:-
Quality
By setting and surpassing higher standards, we will continue to build a smarter, faster, more
efficient organization that delivers excellent, appropriate care in the right place at the right time.
Compassion
Our culture of caring will be unmistakable in every personal interaction as we treat individuals,
families and colleagues with empathy, honesty and openness.
Respect
We will treat each individual with caring consideration and value the diverse perspectives each
one of them can bring.
Collaboration
By w.
Did colonial rule freeze colonized societies by preserving old s.pdfjyothimuppasani1
Did colonial rule \"freeze\" colonized societies by preserving old social and economic patterns,
or was colonial rule a disruptive force of change?
Provide specific evidence to support each side of this question.
Solution
Transforming: Colonial rule gave African women greater autonomy in their day to day lives,
some of whom took advantage of trade.
New opportunities were also offered to cash crop farmers who were able to use colonial trade
networks for their own benefit.
Large scale conversion of some populations to Christianity
A minority got Western educations, which transformed their lives and their vision of their
society.
Preserving: No colonial society underwent Japanese-style industrialization.
Colonial societies engages mostly in primary economic activities, such as agriculture.
Colonialism stunted the growth of the middle class, creating unstable societies.
The practice of ruling through established authorities maintained the status quo..
Do you think that nonhuman animals have interests Does this mean th.pdfjyothimuppasani1
Do you think that nonhuman animals have interests? Does this mean that they also have rights?
Explain.
Solution
Human beings are living beings and so are the animals. A man is a known as a social animal only
because he has the ability to speak and interact in a more civilized way than any other animals.
But having said that, the rights surrounding to the human beings such as the ‘Right to live’,
remains the same even for the feral human beings who are such humans who are raised in the
Jungle and are isolated for some reason from the human world or contact. In this regard, if one
cannot distinguish a feral child, who can simply screech or crawl, rather than walk on two legs
and behave more like animals than like humans, from that of any other civilized human being,
then such a distinguished nature of human beings towards the nonhuman animals, is simply a
biased opinion. Animals are mute. They cannot speak for themselves. But they too have a heart
that throb like a human. They feel hunger. They feel the pain too. Even they long
companionship. They long for a community of their own to co-stay. Hence, I do believe
nonhuman animals do have interests. In such a case, they also have rights. They are simply
helpless because they are unable to reach us out in our ways. But that is not their fault. Perhaps
the rule of nature. The nature requires all to co-exist and hence the Noah’s ark once gave shelter
to creatures of all kind and not just restricted to the mankind. Even the nature wants the creatures
to live in harmony and that is possible when we do not invade their territory but of course, let not
them invade ours too. However, in today’s world, man’s greed has unturned the entire balanced
eco-cycle. We have deeply penetrated into the woods and concretized the Jungle to the extent
that we have quite literally done away with the interests of these nonhuman animals. For the
balanced eco-system, the contribution of the nonhuman animals have also been very significant.
But in a course of time, we snatched away their rights. Yes, we have laws in place to protect the
near-to-extinct animals or to stop killing or preying the nonhuman animals for organs selling and
other purposes. However, the illegal exploitation of these nonhuman animals have only helped us
think that perhaps the interests of the nonhumans or their rights are of much lesser importance
than that of the pleasure of the human beings for the only reason being that we, the humans can
speak and represent for ourselves. In the mask of civilization, we are rather heading to a more
sophisticated way of demeaning the rights of the animals or their interests..
Discuss the importance of recognizing and implementing different ent.pdfjyothimuppasani1
Discuss the importance of recognizing and implementing different entry strategies and
organizational arrangements which result in shared control and oversight through collaborative
relationships
Solution
Entry strategies are explained as a well planned method through which the company decide to
delivery its good and services to the targeted market.
The different types of market entry strategies and organizational arrangement and its importance
are discussed below:
1 .Exporting: when goods/Product are produced in one country and marketed in another country
then it is known as exporting.
2. Licensing: When a firm permit the company operating in another company to use its
manufacturing process, copyrights, and trademark with specific and determined payment.
3. Franchising: It’s an agreement between two companies, where a company (the franchiser)
gives all its rights to another company (the franchisee) to use its trademark, manufacturing
process and market to certain specification.
4. Joint venturing: In this two companies or investors share ownership and control over the
finance and operations of the firm.
5. Contract Manufacturing: In this the company operating in foreign countries gets into contract
to with the country operating there for manufacturing or assembling of the product.
6. Merger & Acquisitions: It is defined as restructuring of organization, for positive growth and
value. Merger means to ‘merge’ in which two companies legally merge into one into one entity,
whereas an acquisition means when one company takes over another and completely become
new owner.
All the entry strategies discussed above results in shared control through collaborative
relationships..
Considering the challenges she is facing, what Anitas plan before .pdfjyothimuppasani1
Considering the challenges she is facing, what Anita\'s plan before the strategic planning retreat?
How would you reformulate the art center mission, has the center need a new strategy? why or
why not?
Solution
Anitha wants to bring some new innovation arts to the Arts center. This also brings more profit
for her. People who are crazy of arts expect more attractive and interesting arts,so she has to
increase her quality of arts to entertain the art lovers. Few people who don\'t have any knowledge
about arts also started trying out with arts. The art center mission can be reformulated by
inspiring them in participating in performances and they have to feel that what time they have
towards arts must be meaningful.
The strategy that can be used by sponsoring and contributing. This work can get help by adding
partners also. Through this they can teach others and also bring their talents out. By performing
like this the whole community gets attracted and her dream comes true. Through this they can
bring out the most hidden artists in the community and many artists are come out showing their
excellence in their art..
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfjyothimuppasani1
Data Structure in C++
Doubly Linked Lists of ints
http://staffwww.fullcoll.edu/aclifton/courses/cs133_fa16/files/dlist.h
This is my code below: dlist.cc
-------------------------------------------------------------------------------------------------------
#include
#include \"dlist.h\"
dlist::node* dlist::at(int n){
node* c = _head;
while(n > 0 && c){
c = c->next;
n--;
}
return c;
}
void dlist::insert(node* previous, int value){
node* n = new node{value, previous->next};
previous->next = n;
}//update tail
void dlist::del(node* which){
node* nn = which->next;
which->next = nn->next;
delete nn;
}
void dlist::push_back(int value){
node* n = new node{value, nullptr};
_tail->next = n;
_tail-> n;
}
void dlist::push_front(int value){
node* n = new node(value, nullptr);
_head->prev = n;
_head-> n;
}
void dlist::pop_front(){
node* n = _head;
_head = _head->next;
delete n;
}
void dlist::pop_back(){
node* n = _tail;
_tail = _tail->prev;
delete n;
}
int dlist::size() {
node* c = _head;
int s = 0;
while(c){
s++;
c = c->next;
}
return s;
}
--------------------------------------------------------------------------------
Please fix and complete my code, and I also need whole code contatining main function for
testing dlist.cc In this assignment, you will implement a doubly-linked list class. together with
some list operations. To make things easier, you\'ll implement a list of int rather than a template
class pragma once dlist. h Doubly linked lists of ints include Kostream class dlist public: d list
struct node int value node next node prev; node\' head() const return -head; node\" tail() const t
return -tail Implement ALL the following methods Returns the node at a particular index (0 is the
head node at(int) Insert a new value, after an existing one void insert(node *previous int value
Delete the given node void del (node which)
Solution
#include
#include
#include
/*
* Node Declaration
*/
using namespace std;
struct node
{
int value;
string name;
struct node *next;
struct node *prev;
}*start;
/*class declaration
class dlist
{
public:
void create_list(int value);
void push_front(int value);
void push_back(int value, int position);
void pop_front(int value);
void pop_back(int value);
void display_dlist();
void reverse();
dlist()
{
start = NULL;
head=NULL;
last=NULL;
}
bool empty() const { return head==NULL; }
friend ostream& operator<<(ostream& ,const dlist& );
void insert(const string& );
void remove(const string& );
private:
node* head() const { return _head; }
node* tail() const { return _tail; }
};
dlist.cc:
/* Create Double Link List*/
void dlist::create_list(int value)
{
struct node *s, *temp;
temp = new(struct node);
temp->info = value;
temp->next = NULL;
if (start == NULL)
{
temp->prev = NULL;
start = temp;
}
else
{
s = start;
while (s->next != NULL)
s = s->next;
s->next = temp;
temp->prev = s;
}
}
/*
* Insertion at the beginning
*/
void dlist::add_begin(int value)
{
if (start == NULL)
{
cout<<\"First Create the list.\"<prev = NULL;
temp->info = val.
Conceptual skills are most important at theSolutionConceptual .pdfjyothimuppasani1
Conceptual skills are most important at the
Solution
Conceptual skills relate to the managers\' mental ability to coordinate and integrate all of the
organization\'s interests and activities. It is about thinking in the abstract and observing
relationships between forces that many others may not be able to see and to take a global
perspective of the organization and its environment. This is not so relevant at the lower level of
management and is most important at the top management level because the senior managers
must look for and exploit unseen opportunities for their organizations..
A variable whose scope is restricted to the method where it was decl.pdfjyothimuppasani1
A variable whose scope is restricted to the method where it was declared is known as a(n)
parameter
global variable
local variable
public instance data
private instance data
parameter
global variable
local variable
public instance data
private instance data
Solution
Answer is \"Local Variable\"
Parameter: parameter is something which is passed to the method, and not declared in the
method.
Global Variable: Global Variable is accessible from anywhere in the program. And not just
restricted to a certain method..
•Design (create) 3 questions for a quiz show game and design regular.pdfjyothimuppasani1
•Design (create) 3 questions for a quiz show game and design regular expressions that validate
the answers. The challenge is to be no more and no less exacting than a human checker. I have
the sample quiz done already.email me for code
Solution
Database design
• Not easy!
• Will discuss formal methods next week
• Review: databases are made up of
– Tables: tables made up of
• Records: records made up of fields
• Speaking of rows and columns is misleading
• Critical issue: fixed number of fields, though a
specific field may be optional (aka not required)
– NOT NULL in MySQL jargon means required!
– MySQL does support variable length strings.
Data types
• Terminology varies for different DBMS
products
• Performance (speed) of operations varies
with different datatypes
• Size varies with different datatypes
• Performance and size limits are points of
competition among the different products
MySQL datatypes: numbers
• INT (aka INTEGER), can be UNSIGNED
(Size 4 bytes = 32 bits)
• TINYINT, SMALLINT, MEDIUMINT,
BIGINT
– Different sizes
• float (4 bytes), double (8 bytes), can
specify precision within these limits
• more
MySQL datatypes, strings
• CHAR(specified length)
• VARCHAR(maximum length)
• TINYBLOB short, variable length string,
up to 255 characters
• BLOB, TEXT variable length string
• MEDIUMBLOB, MEDIUMTEXT,
LONGBLOB, LONGTEXT
MySQL datatypes: enum
• ENUM
– Specify one of a set of values
– Stored as an integer, with 0 indicated unset or
not in the specified set
– Doing this may be more efficient because
built-in MySQL routines do the searching
MySQL datatypes: date/time
• DATE
• TIME
• DATETIME
• YEAR
• TIMESTAMP
Tables
• Specify one field as the primary key
• Primary keys are unique IN THAT TABLE
– Let the DBMS create the primary key OR
– Depend on intrinsic value that is guaranteed to be
unique
• Email addresses
• ISBN numbers
• ?
• A field in one table may be a foreign key. This is
a reference to a primary key in another table (or
this table). MORE ON THIS LATER.
Database
• Assume database itself is created for us
AND we have permissions to create new
tables.
• NOTE: permissions can be set by MySQL
commands, including queries sent by php.
• Start off talking general SQL and then
specific php and MySQL
Create table example
• CREATE TABLE movies (
mid INT NOT NULL AUTO_INCREMENT
PRIMARY KEY,
mname CHAR(30),
mdesc TEXT,
myear YEAR
)
Create table example
CREATE TABLE players (
pid INT NOT NULL AUTO_INCREMENT
PRIMARY KEY,
pname CHAR(30),
score INT NOT NULL,
lastplayed DATE
)
Create example
CREATE TABLE games (
gid INT NOT NULL AUTO_INCREMENT
PRIMARY KEY,
pid INT,
gtime TIMESTAMP,
score INT
)
The pid field will refer to / have the value of
the pid field (the primary key) of a specific
player. Here in this table, it is called a
foreign key.
Foreign keys
• Some versions of MySQL (and other DBMS)
have ways to specify the the pid value is a
foreign key
pid INT REFERENCE players
• The DBMS will check to make sure it is a valid
value.
• Since the php.
You are to write a GUI program that will allow a user to buy, sell a.pdfjyothimuppasani1
You are to write a GUI program that will allow a user to buy, sell and view stocks in a stock
portfolio.
Objective:
Write a GUI program that maintains a cash balance, list of stock holdings, supports buying and
selling of stocks and displays the current portfolio inventory.
Program Capabilities:
1. Allow a user to buy a stock with a given number of shares and price per share.
2. Display the current portfolio (stock ticker, number of shares, initial price).
3. Update the portfolio display for purchases and sales.
4. Allow the user to sell all of the shares of a given stock.
5. Give the user an initial cash balance, and update and display the balance according to the
user\'s purchases and sales.
6. Ignore any transaction that causes the cash position to go below $0.
USE OF PREVIOUS StockHolding and PortfolioList LABS IS ADVISED. (I\'ve including my
solutions to these below)
This is my written code from earlier homework:
public class StockHolding {
private String ticker;
private int numShares;
private double initialSharePrice;
private double currentSharePrice;
public StockHolding(String ticker, int numberShares, double initialPrice) {
this.ticker = ticker;
numShares = numberShares;
initialSharePrice = initialPrice;
currentSharePrice = initialPrice;
}
public double getCurrentValue() {
return numShares * getCurrentSharePrice();
}
public double getInitialCost() {
return numShares * getInitialSharePrice();
}
public double getCurrentProfit() {
return getCurrentValue() - getInitialCost();
}
public double getCurrentSharePrice() {
return currentSharePrice;
}
public void setCurrentSharePrice(double currentSharePrice) {
this.currentSharePrice = currentSharePrice;
}
public String getTicker() {
return ticker;
}
public int getShares() {
return numShares;
}
public double getInitialSharePrice() {
return initialSharePrice;
}
@Override
public String toString() {
return \"Stock \" + ticker + \", \" + numShares + \", shares bought at \"
+ initialSharePrice + \", current price \"
+ currentSharePrice;
}
}
AND
import java.util.ArrayList;
public class PortfolioList {
private ArrayList portfolio;
public PortfolioList() {
portfolio = new ArrayList();
}
public void add(StockHolding stock) {
portfolio.add(stock);
}
public StockHolding find(String ticker) {
for (int i = 0; i < portfolio.size(); i++) {
StockHolding sh = portfolio.get(i);
if (sh.getTicker().equals(ticker)) {
return sh;
}
}
return null;
}
public void remove(String ticker) {
int pos = -1;
for (int i = 0; i < portfolio.size(); i++) {
StockHolding sh = portfolio.get(i);
if (sh.getTicker().equals(ticker)) {
pos = i;
}
}
if (pos != -1) {
portfolio.remove(pos);
}
}
I\'ve been staring at this for two days, and I am lost. Please, any guidance/help would be greatly
appreciated.
Honestly don\'t even need a full solution, just need something to kick start. A comment skeleton
would help a ton. Thanks!
Solution
SOURCE CODE:
package stock;
public class StockHolding {
private String ticker;
private int numShares;
private do.
write the To Dos to get the exact outputNOte A valid Fraction .pdfjyothimuppasani1
write the To Do\'s to get the exact output:
NOte: A valid Fraction number has a non-negative numerator and a positive denominator.
Default constructor initializes the object to safe empty state (an object with denom equals -1).
The two-argument constructor also validates the parameters and sets the object to the safe empty
state if the parameters are not valid.
Write the definitions and prototypes of following functions in Fraction.cpp and Fraction.h
respectively (They are indicated in the files by //TODO tag):
Define isEmpty function as a member function, which returns true if the object is in safe empty
state (an object is in the safe empty state if denominator (denom) equals -1).
Define display function, which sends a Fraction number to the output stream (with the
“Numerator/denominator” format). This function just prints \"Invalid Fraction Object!\" in the
screen if the object is in the safe empty state. In case that object denominator equals 1, it just
print the numerator.
Define the operator functions for the following operators:
“+=”, “+”, “*”
The overload of the above operators should make the following code possible:
The member operator+ : Adds two Fraction numbers and returns a Fraction number as the result.
This function returns an object with the safe empty state if either of Fraction numbers (operands)
is in safe empty state. It makes following code possible:
A+B ( where A and B are Fraction objects)
The member operator+= : Adds two Fraction numbers and assigns the result to the left operand,
then returns a reference to the left operand. If either of Fraction numbers (operands) is in safe
empty state, it initializes the left operand to the safe empty state, then returns a reference to the
left operand. It makes following code possible:
A+=B ( where A and B are Fraction objects)
The member operator* : Multiplies two Fraction numbers and returns a Fraction number as the
result. This function returns an object with the safe empty state if either of Fraction numbers
(operands) is in safe empty state. It makes following code possible:
A*B ( where A and B are Fraction objects)
fraction.cpp
#include \"Fraction.h\"
using namespace std;
namespace sict{
Fraction::Fraction(){
denom =-1; // safe empty state
}
Fraction::Fraction(int n, int d) // n: numerator, d: denominator
{
if(n >= 0 && d > 0){
num = n;
denom = d;
reduce();
}
else
denom =-1; // set to safe empty state
}
int Fraction::gcd() // returns the greatest common divisor of num and
denom
{
int mn = min(); // min of num and denom
int mx = max(); // mX of num and denom
for (int x=mn ; x > 0 ; x--) // find the greatest common divisor
if( mx % x == 0 && mn % x == 0)
return x;
return 1;
}
void Fraction::reduce() // simplify the Fraction number
{
int tmp = gcd();
num /= tmp;
denom /= tmp;
}
int Fraction::max ()
{
return (num >= denom) ? num : denom;
}
int Fraction::min()
{
return (num >= denom) ? denom : num;
}
// in_lab
// TODO: write the implementation of display function HERE
// TODO: w.
What are the factors that contribute to H+ gain or loss How do lung.pdfjyothimuppasani1
What are the factors that contribute to H+ gain or loss? How do lungs and the kidneys balance or
regulate the changes in pH?
Solution
Answer=
Factors that contribute to loss or gain of H ions are=
CO2 concentration
O2 concentration
bicarbonate concentration in urine
The lungs regulate the changes in PH = Acid base imbalances in the bloods pH can be altered by
changes in breathing to expel ,ore CO2 & raise the pH back to normal
Hydrogen ions are carried in the blood along with oxygen & carbon dioxide
60 % CO2 is carried as a dissolved bicarbonate
A small amount of CO2 is carried on Haemoglobin as carbaminohaemoglobin which is
transported to the lungs for removal
Acid base imbalances that overcome the buffer system can be compensated in the short term by
changing the rate of ventilation
When pH of blood drops too low ,the body compensates by increasing breathing to expel more
CO2 & during alkalemia the inspiration occurs
Regulation of pH by kidneys =
kidneys have 2 important roles in maintaining the acid -base balance
1]They reabsorb bicarbonate from urine
2] they excrete hydrogen ions into urine
The major homeostatic control point for maintaining a stable pH balance is renal excretion
Bicarbonate does not have transporter ,so its reabsorption involves a series of reactions in the
tubule lumen & tubular epithelium .
In response tyo acidosis the tubular cells reabsorb more bicarbonate from the tubular fluid ,& the
collecting cells secrete more hydrogen & generate more bicarbonate
In response to alkalosis ,the kidneys may excrete more bicarbonate by decreasing Hydrogen ion
secretion from tubular epithelial cells ,& lowering the rates of glutamine metabolism &
ammonium excretion.
Write down the four (4) nonlinear regression models covered in class,.pdfjyothimuppasani1
Write down the four (4) nonlinear regression models covered in class, i.e. both the name of the
model and their functional form showing their respective regression coefficients. A rapidly
growing bacteria has been discovered with a growth rate as shown in the table. Analyze this date
using a power law model. First linearize the data in the table based on the power law model, call
this new linearized data x and y. Next, determine the coefficients a_0 and a_1 of a linear
regression y = a_0 + a_1x for the linearized power law data x and y, and compute the correlation
coefficient for the liner regression. Note that you are not being asked to do a linear regression of
the data in the table but rather a linear regression of the linearized version of that data. Once you
compute a_0 and a_1 use these to determine the coefficients of the power law model. Write a
Matlab script that uses the polyfit function to determine the regression coefficients of a second
order polynomial fit to data in the table. In the same script, write down the code for using the
polyval command to determine the value of the regression curve at the observed times.
Solution
Nonlinear regression is a statistical technique that helps describe nonlinear relationships in
experimental data. A nonlinear regression model can be written Yn = f(xn, ) + Zn where f is the
expectation function and xn is a vector of associated regressor variables or independent variables
for the nth case.
A nonlinear model is one in which at least one of the parameters appears nonlinearly. More
formally, in a nonlinear model, at least one derivative with respect to a parameter should involve
that parameter. Examples of a nonlinear model are:
Y(t) = exp(at+bt2)
Y(t) = at + exp(-bt).
Important non linear growth models
1.Logistic Model
This model is represented by the differential equation
dN/dt = rN (1-N/K).
Integrating, we get
N(t) = K / [1+(K/No-1) exp(-rt)]
The graph of N(t) versus t is elongated S-shaped and the curve is symmetrical about its point of
inflexion.
2.Malthus Model
If N(t) denotes the population size or biomass at time t and r is the intrinsic growth rate, then the
rate of growth of population size is given by
dN/dt = rN.
Integrating, we get
N(t) = No exp (rt),
where No denotes the population size at t=0. Thus this law entails an exponential increase for
r>0. Furthermore, N(t) à as t à , which cannot happen in reality.
3. Monomolecular Model
This model describes the progress of a growth situation in which it is believed that the rate of
growth at any time is proportional to the resources yet to be achieved, i.e.
dN/dt = r(K-N),
where K is the carrying size of the system. Integrating (3.3), we get
N(t) = K-(K-No) exp (-rt).
4. Richards Model.
This model is given by dN/dt = rN (KN – Nm)/mKm which, on integration, gives N(t )=K N0 /[
N0+ (KN – N0m) exp (-rt)]1/m.
Unlike the earlier models, this model has four parameters
Hours (H)
10
20
40
50
No fo bacteria (N)
25
70
380
550
610
b)
N = b H m
Log10.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
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.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Help please!!(Include your modified DList.java source code file in.pdf
1. Help please!!
(Include your modified DList.java source code file in your homework solution zip archive)
Using
whatever Java IDE you prefer, create a project and add DList.java and DListTest.java to it (these
files are provided
in the Week 6 Source zip archive). Modify DList to implement a method that removes all
occurrences of a specific
integer from the list. Here is the pseudocode:
Method removeAll(In: Integer pData) Returns Nothing
Define index variable i and initialize i to 0
While i < the size of this Dlist Do
If get(i) equals pData Then
remove(i)
Else
Increment i
End If
End While
End Method removeAll
Next, modify DListTest() to add test case 21 which tests that removeAll() works correctly.
WHat more do i need to provide to get help on this???
Solution
/* DListNode.java */
/**
* A DListNode is a node in a DList (doubly-linked list).
*/
class DListNode {
/**
* item references the item stored in the current node.
* prev references the previous node in the DList.
* next references the next node in the DList.
*
* DO NOT CHANGE THE FOLLOWING FIELD DECLARATIONS.
2. */
public Object item;
protected DListNode prev;
protected DListNode next;
/**
* DListNode() constructor.
* @param i the item to store in the node.
* @param p the node previous to this node.
* @param n the node following this node.
*/
DListNode(Object i, DListNode p, DListNode n) {
item = i;
prev = p;
next = n;
}
}
/* DList.java */
/**
* A DList is a mutable doubly-linked list ADT. Its implementation is
* circularly-linked and employs a sentinel (dummy) node at the head
* of the list.
*
* DO NOT CHANGE ANY METHOD PROTOTYPES IN THIS FILE.
*/
class DList {
/**
* head references the sentinel node.
* size is the number of items in the list. (The sentinel node does not
* store an item.)
*
* DO NOT CHANGE THE FOLLOWING FIELD DECLARATIONS.
*/
protected DListNode head;
protected int size;
/* DList invariants:
3. * 1) head != null.
* 2) For any DListNode x in a DList, x.next != null.
* 3) For any DListNode x in a DList, x.prev != null.
* 4) For any DListNode x in a DList, if x.next == y, then y.prev == x.
* 5) For any DListNode x in a DList, if x.prev == y, then y.next == x.
* 6) size is the number of DListNodes, NOT COUNTING the sentinel,
* that can be accessed from the sentinel (head) by a sequence of
* "next" references.
*/
/**
* newNode() calls the DListNode constructor. Use this class to allocate
* new DListNodes rather than calling the DListNode constructor directly.
* That way, only this method needs to be overridden if a subclass of DList
* wants to use a different kind of node.
* @param item the item to store in the node.
* @param prev the node previous to this node.
* @param next the node following this node.
*/
protected DListNode newNode(Object item, DListNode prev, DListNode next) {
return new DListNode(item, prev, next);
}
/**
* DList() constructor for an empty DList.
*/
public DList() {
// Your solution here.
head = newNode(null, head, head);
head.prev = head;
head.next = head;
size = 0;
}
/**
* isEmpty() returns true if this DList is empty, false otherwise.
* @return true if this DList is empty, false otherwise.
* Performance: runs in O(1) time.
*/
4. public boolean isEmpty() {
return size == 0;
}
/**
* length() returns the length of this DList.
* @return the length of this DList.
* Performance: runs in O(1) time.
*/
public int length() {
return size;
}
/**
* insertFront() inserts an item at the front of this DList.
* @param item is the item to be inserted.
* Performance: runs in O(1) time.
*/
public void insertFront(Object item) {
// Your solution here.
head.next.prev = newNode(item, head, head.next);
head.next = head.next.prev;
size++;
}
/**
* insertBack() inserts an item at the back of this DList.
* @param item is the item to be inserted.
* Performance: runs in O(1) time.
*/
public void insertBack(Object item) {
// Your solution here.
head.prev.next = newNode(item, head.prev, head);
head.prev = head.prev.next;
size++;
}
/**
* front() returns the node at the front of this DList. If the DList is
* empty, return null.
5. *
* Do NOT return the sentinel under any circumstances!
*
* @return the node at the front of this DList.
* Performance: runs in O(1) time.
*/
public DListNode front() {
// Your solution here.
if (isEmpty()) {
return null;
}
return head.next;
}
/**
* back() returns the node at the back of this DList. If the DList is
* empty, return null.
*
* Do NOT return the sentinel under any circumstances!
*
* @return the node at the back of this DList.
* Performance: runs in O(1) time.
*/
public DListNode back() {
// Your solution here.
if (isEmpty()) {
return null;
}
return head.prev;
}
/**
* next() returns the node following "node" in this DList. If "node" is
* null, or "node" is the last node in this DList, return null.
*
* Do NOT return the sentinel under any circumstances!
*
* @param node the node whose successor is sought.
6. * @return the node following "node".
* Performance: runs in O(1) time.
*/
public DListNode next(DListNode node) {
// Your solution here.
if (node == null || node.next == head) {
return null;
}
return node.next;
}
/**
* prev() returns the node prior to "node" in this DList. If "node" is
* null, or "node" is the first node in this DList, return null.
*
* Do NOT return the sentinel under any circumstances!
*
* @param node the node whose predecessor is sought.
* @return the node prior to "node".
* Performance: runs in O(1) time.
*/
public DListNode prev(DListNode node) {
// Your solution here.
if (node == null || node.prev == head) {
return null;
}
return node.prev;
}
/**
* insertAfter() inserts an item in this DList immediately following "node".
* If "node" is null, do nothing.
* @param item the item to be inserted.
* @param node the node to insert the item after.
* Performance: runs in O(1) time.
*/
public void insertAfter(Object item, DListNode node) {
// Your solution here.
7. if (node != null) {
node.next.prev = newNode(item, node, node.next);;
node.next = node.next.prev;
size++;
}
}
/**
* insertBefore() inserts an item in this DList immediately before "node".
* If "node" is null, do nothing.
* @param item the item to be inserted.
* @param node the node to insert the item before.
* Performance: runs in O(1) time.
*/
public void insertBefore(Object item, DListNode node) {
// Your solution here.
if (node != null) {
node.prev.next = newNode(item, node.prev, node);
node.prev = node.prev.next;
size++;
}
}
/**
* remove() removes "node" from this DList. If "node" is null, do nothing.
* Performance: runs in O(1) time.
*/
public void remove(DListNode node) {
// Your solution here.
if (node != null) {
node.prev.next = node.next;
node.next.prev = node.prev;
size--;
}
}
/**
* removeAll() removes "node" from this DList. If "node" is null, do nothing.
* Performance: runs in O(1) time.
8. */
public void removeAll(Object item) {
// Your solution here.
int i=0;
DListNode current = head.next;
while (current != head) {
if (current.item == item ) remove(current);
current = current.next;
}
if (current.item == item) remove(current);
}
/**
* toString() returns a String representation of this DList.
*
* DO NOT CHANGE THIS METHOD.
*
* @return a String representation of this DList.
* Performance: runs in O(n) time, where n is the length of the list.
*/
public String toString() {
String result = "[ ";
DListNode current = head.next;
while (current != head) {
result = result + current.item + " ";
current = current.next;
}
return result + "]";
}
public static void main(String[] argv) {
System.out.println("Testing Constructor");
DList testList = new DList();
System.out.println("Is empty? Should be true: " + testList.isEmpty());
System.out.println("Should be zero length: " + testList.length());
System.out.println("Should be [ ]: " + testList);
System.out.println(" Testing insertFront");
9. testList.insertFront(1);
System.out.println("Is empty? Should be false: " + testList.isEmpty());
System.out.println("Should be one length: " + testList.length());
System.out.println("Should be [ 1 ]: " + testList);
System.out.println(" Testing insertBack");
testList.insertBack(3);
System.out.println("Is empty? Should be false: " + testList.isEmpty());
System.out.println("Should be two length: " + testList.length());
System.out.println("Should be [ 1 3 ]: " + testList);
System.out.println(" Testing front()");
System.out.println("This should print out 1: " + testList.front().item);
System.out.println(" Testing back()");
System.out.println("This should print out 3: " + testList.back().item);
System.out.println(" Testing next method");
testList.insertFront(5);
System.out.println("Should be [ 5 1 3 ]: " + testList);
DListNode testingNode = testList.next(testList.front());
System.out.println("This should print out 1: " + testingNode.item);
testingNode = testList.next(testingNode);
System.out.println("This should print out 3: " + testingNode.item);
System.out.println(" Testing prev method");
testingNode = testList.prev(testingNode);
System.out.println("This should print out 1: " + testingNode.item);
System.out.println(" Testing insertBefore");
testList.insertBefore(10, testingNode);
System.out.println("Should print out [ 5 10 1 3 ]: " + testList);
System.out.println(" Testing insertAfter");
testList.insertAfter(40, testingNode);
System.out.println("Should be [ 5 10 1 40 3 ]: " + testList);
System.out.println(" Removing node");
testList.remove(testingNode);
System.out.println("Should be [ 5 10 40 3 ]: " + testList);
System.out.println(testList.length());
DList l = new DList();
System.out.println(" ###Testing insertFront ### Empty list is" + l);
l.insertFront(9);
10. System.out.println(" Inserting 9 at front. List with 9 is " + l);
l.insertFront(8);
l.insertFront(7);
System.out.println(" Inserting 7, 8 at the front. List with 7, 8, 9 is " + l);
l.insertAfter(6, l.head);
System.out.println(" Inserting 6 after head. nList with 6, 7, 8, 9 is "+l);
l.remove(l.head.next);
System.out.println(" Removed head.next, should return a list of 7, 8, 9. List with 7, 8, 9 is
" + l);
l.insertFront(9);
l.insertFront(8);
System.out.println(" Inserting List 9,8 with 8, 9, 7, 8, 9 is " + l);
l.removeAll(8);
System.out.println(" Removing all 8 from List with 9, 7, 9 is " + l);
}
}
Output refer url : http://ideone.com/Ila9vB