Implement a priority queue using a DoublyLinkedList where the
node with the highest priority (key) is the right-most node.
The remove (de-queue) operation returns the node with the highest
priority (key).
If displayForward() displays List (first-->last) : 10 30 40
55
remove() would return the node with key 55.
Demonstrate by inserting keys at random, displayForward(), call
remove then displayForward() again.
You will then attach a modified DoublyLinkedList.java (to
contain the new priorityInsert(long key) and priorityRemove()
methods).
Use the provided PQDoublyLinkedTest.java to test your code.
I cant get PQDoublyLinkedTest to work with my code. I already got the rest of code working. Please comment if you want me to add the rest of the code.
PLEASE DO NOT MODIFY PQDoublyLinkedTest!!! its just for testing the code.
public class PQDoublyLinkedTest
{
public static void main(String[] args)
{ // make a new list
DoublyLinkedList theList = new DoublyLinkedList();
theList.priorityInsert(22); // insert at front
theList.priorityInsert(44);
theList.priorityInsert(66);
theList.priorityInsert(11); // insert at rear
theList.priorityInsert(33);
theList.priorityInsert(55);
theList.priorityInsert(10);
theList.priorityInsert(70);
theList.priorityInsert(30);
theList.displayForward(); // display list forward
Link2 removed = theList.priorityRemove();
System.out.print("priorityRemove() returned node with key:
");
removed.displayLink2();
} // end main()
} // end class PQDoublyLinkedTest
public class DoublyLinkedList
{
private Link first; // ref to first item
private Link last; // ref to last item
public DoublyLinkedList() // constructor
{
first = null; // no items on list yet
last = null;
}
public boolean isEmpty() // true if no links
{
return first == null;
}
public void insertFirst(long dd) // insert at front of
list
{
Link newLink = new Link(dd); // make new link
if (isEmpty()) // if empty list,
last = newLink; // newLink <-- last
else
first.previous = newLink; // newLink <-- old first
newLink.next = first; // newLink --> old first
first = newLink; // first --> newLink
}
public void insertLast(long dd) // insert at end of list
{
Link newLink = new Link(dd); // make new link
if (isEmpty()) // if empty list,
first = newLink; // first --> newLink
else {
last.next = newLink; // old last --> newLink
newLink.previous = last; // old last <-- newLink
}
last = newLink; // newLink <-- last
}
public Link deleteFirst() // delete first link
{ // (assumes non-empty list)
Link temp = first;
if (first.next == null) // if only one item
last = null; // null <-- last
else
first.next.previous = null; // null <-- old next
first = first.next; // first --> old next
return temp;
}
public Link deleteLast() // delete last link
{ // (assumes non-empty list)
Link temp = last;
if (first.next == null) // if only one item
first = null; // first --> null
else
last.previous.next = null; // old previous --> null
last = last.previous; // old previous <-- last
return temp;
}
// insert dd just after key
public boolean insertAfter(long key, long dd)
{ // (assumes non-empty list)
Link current = first; // start at beginning
while (current.dData != key) // until match is found,
{
current = current.next; // move to next link
if (current == null)
return false; // didn't find it
}
Link newLink = new Link(dd); // make new link
if (current == last) // if last link,
{
newLink.next = null; // newLink --> null
last = newLink; // newLink <-- last
} else // not last link,
{
newLink.next = current.next; // newLink --> old next
// newLink <-- old next
current.next.previous = newLink;
}
newLink.previous = current; // old current <-- newLink
current.next = newLink; // old current --> newLink
return true; // found it, did insertion
}
public Link deleteKey(long key) // delete item w/ given
key
{ // (assumes non-empty list)
Link current = first; // start at beginning
while (current.dData != key) // until match is found,
{
current = current.next; // move to next link
if (current == null)
return null; // didn't find it
}
if (current == first) // found it; first item?
first = current.next; // first --> old next
else
// not first
// old previous --> old next
current.previous.next = current.next;
if (current == last) // last item?
last = current.previous; // old previous <-- last
else
// not last
// old previous <-- old next
current.next.previous = current.previous;
return current; // return value
}
public void displayForward()
{
System.out.print("List (first-->last): ");
Link current = first; // start at beginning
while (current != null) // until end of list,
{
current.displayLink(); // display data
current = current.next; // move to next link
}
System.out.println("");
}
public void displayBackward()
{
System.out.print("List (last-->first): ");
Link current = last; // start at end
while (current != null) // until start of list,
{
current.displayLink(); // display data
current = current.previous; // move to previous link
}
System.out.println("");
}
public void insertSorted(long key)
{
// if list is empty or key is less than current first, inserting
at
// first
if (isEmpty() || key < first.dData) {
insertFirst(key);
return; // exiting method
}
// taking a reference to first
Link current = first;
// looping as long as current.next is not null
while (current.next != null) {
// checking if key can be added between current and
current.next
if (key >= current.dData && key <=
current.next.dData) {
// adding between current and current.next and updating all
// links
Link lnk = new Link(key);
lnk.next = current.next;
current.next.previous = lnk;
current.next = lnk;
lnk.previous = current;
return; //exiting
}
//otherwise, advancing to next link
current = current.next;
}
//if the element is still not inserted, adding to the end
insertLast(key);
}
} // end class DoublyLinkedList
class Link
{
public long dData; // data item
public Link next; // next link in list
public Link previous; // previous link in list
public Link(long d) // constructor
{
dData = d;
}
public void displayLink() // display this link
{
System.out.print(dData + " ");
}
} // end class Link
In: Computer Science
|
Beyond Bankruptcy: How Failed Stores Come Back Online By Erica E. Phillips and Stephanie Gleason | Aug 05, 2017 TOPICS: Bankruptcy, Brand Management, Business Models, Costs, E-Commerce SUMMARY: You may recognize some of the brands in this article. One thing they have in common is that their companies went bankrupt and closed stores, but the brand lives on. Bankruptcy might mean the end of a company, but not the end of a brand. There is value to a recognized brand even if the business model for selling it was not a success. Selling apparel online costs less, although it is also interesting to note differences in the kinds of costs as shown in the diagram "A Leg Up". A brand from a bankrupt company in the retail clothing industry has value, but that value depreciates as time passes if e-commerce sales do not begin quickly. Transitioning to entirely online sales has challenges that include lining up new designers and manufacturers and setting up distribution networks for ship-to-home sales. Companies that buy brands after bankruptcy view online only sales as a short-term solution. The goal is to return brands to department stores and boutiques. CLASSROOM APPLICATION: The story of bankrupt brands that hope to find new life as e-commerce companies helps show the value of brands and innovative ways to transform them after bankruptcy. Although initial efforts involve creating online-only brands, the long-term plan is to return them to retail stores. The long list of brands includes many familiar ones that have recognition with consumers; Wet Seal, BCBG Max Azria, American Apparel, Coldwater Creek and The Limited. These are brands that had brand-specific stores and those locations all closed because of bankruptcy. The online-only value of the brands exists if they can quickly begin selling via e-commerce. As time passes after stores close and before e-commerce sales begin, the value of the brand declines. The diagram "A Leg Up" is way for students to understand and compare e-commerce costs with those of brick-and-mortar stores. There are categories of expenses in each not matched by the other distribution channel, but the biggest number to note is the $27 in store payroll not matched in e-commerce. The diagram can be the foundation of a lengthy discussion about the differences in these two business models. 1. Which brands, if any, did you recognize any in the story? What similarities and differences are there with these brands? |
|
|
2. List the breakdown of costs for offline (retail store) sales of a pair of jeans and compare these costs to the costs for a pair of jeans sold only online. |
|
|
3. List the challenges new owners of brands face as they try to transform the brand to e-commerce (selling online only). |
|
|
4. In your opinion, do you think the long-term goal of selling brands in retail stores is realistic? Why or why not? |
|
|
5. Why does the value of a brand drop quickly after bankruptcy? |
In: Accounting
Ending School Segregation: The Case of Farmville, Virginia
No aspect of segregation was more harmful than the separation of black and white children in public schools, especially in the South. This story is about how black students in 1951 staged a strike in Farmville, Virginia, to protest school segregation. How that strike played a major role in ending school segregation is not widely known. Like many towns in the South, Farmville maintained separate school systems for black and white children. For the black students, it was immediately clear that their school facilities were inferior to those of whites. The story of Farmville is a story of victory, but one long delayed, even long after the Supreme Court’s ruling.
Until the Brown v. Board of Education decision, the relevant legal standard was “separate but equal.” What does Farmville tell you about the enforcement of even that standard? What would have happened if that standard had been strictly enforced?
Farmville is a classic example of de jure discrimination, but most discrimination is de facto. How do we address de facto discrimination?
At the time of the Brown decision, racial discrimination was overt in almost all areas of life. Why do you think that the NAACP selected discrimination in education as its prime target?
Title IX and Girl’s Sports
At America’s birth, the Constitution’s framers granted women almost no civil rights. In fact, it took until 1920 for women to win the right to vote, and until the 1970s to gain overall legal equality. The modern women’s movement adopted several lessons from the Civil Rights Movement. For example, to show they were being discriminated against women had to prove they were treated unfavorably simply because they were women. The story of one fight over equality in youth sports illustrates this ongoing struggle.
Is the scheduling of athletic seasons by the state an example of discrimination?
Does it matter that the different season (different from the boys’)
was combined with unequal facilities?
Should it matter that most people think that different seasons for
the same or comparable sports is acceptable? Does it matter if most
girls find it acceptable?
Fighting for the Rights of Disabled Americans
Fighting discrimination often takes years of mass organization, protest, political lobbying, and legal challenges to win new laws and the power to enforce them. The 1973 Rehabilitation Act was considered an early victory for supporters of rights for the disabled. It included a provision stipulating that federally funded programs and facilities must be accessible to disabled individuals. The broader Americans with Disabilities Act of 1990 expanded the protections first articulated in 1973. But the fight for equality often continues beyond the passage of laws recognizing the rights of those who are experiencing discrimination. No one knows this better than those who seek the end of discrimination against people with disabilities.
What steps are necessary to eliminate discrimination against those with disabilities?
What disabilities should be covered by ADA?
Is discrimination against those with disabilities comparable to discrimination against racial minorities and women?
In: Operations Management
Linear Algebra Conceptual Questions
• What are the possible sizes of solution sets for linear
systems?
• List as many things that are equivalent to a square matrix being nonsingular as you can.
• List as many things that are equivalent to a square matrix being singular as you can. (Should be basically the same as your list above except all opposites) • Give an example of a singular matrix that is NOT just the zero matrix.
• If a system has m equations and n unknowns where m < n, what are the possibilities for number of solutions to the system?
• Rephrase the question above, and your answer to it, in terms of the rank of the coefficient matrix for the system.
In: Advanced Math
Suppose f(x,y)=(x−y)(16−xy).f(x,y)=(x−y)(16−xy). Answer the following.
1. Find the local maxima of f.f. List
your answers as points in the form (a,b,c)(a,b,c).
Answer (separate by commas):
2. Find the local minima of f.f. List
your answers as points in the form (a,b,c)(a,b,c).
Answer (separate by commas):
3. Find the saddle points of f.f. List
your answers as points in the form (a,b,c)(a,b,c).
Answer (separate by commas):
In: Math
Which of the following statements is correct?
| a. |
When you define more than one page (view) in a jQuery Mobile powered HTML document, you distinguish between them by giving each div with data_role of page a unique name. |
|
| b. |
When having more than one page in a jQuery Mobile powered HTML document, they all must share the same header and footer divs. |
|
| c. |
The property data-role="list-dividers" adds list dividers within a jQuery Mobile (un)ordered list. |
|
| d. |
A jQuery Mobile allows you to add icons to buttons and hyperlinks. |
In: Computer Science
Disaster Plans
The SNS is a pivotal tool in the event of a disaster.
· List and explain the types of items a community hospital will require and seek from the SNS in the event of a disaster.
· List and explain at least two concerns you may have when forced to rely on this facility.
· During the creation of disaster plans, it is common and essential that neighboring hospitals work together. List and explain some of the problems that may arise from a disaster plan, which may be ten years old and involved all of the local community hospitals at the time it was originally designed.
Make sure that you include an introduction and conclusion to your post.
In: Nursing
In Python Create customer information system as follows:
Python 3
Ask the user to enter name, phonenumber, email for each customer. Build a dictionary of dictionaries to hold 10 customers with each customer having a unique customer id. (random number generated)
In: Computer Science
Write a program in python that corrects misspelled words. The input for the program is either a string or a list of strings. The output should be a string or a list depending on the input and should have the spellings corrected. The speller should be able to correct at least the words listed below. You are free to use any data structures we have covered so far including lists and dictionaries. Your program should be in autocorrect.py. Here is a list of words that are commonly misspelled: • acquire – aquire, adquire • acquit – aquit • beautiful – beatuful • guarantee – garantee, garentee, garanty • professor – professer • repetition – repitition • until – untill
In: Computer Science
Effective Writing, A handbook for Accountants, 10th Edition
Exercise 1-5 [Ethics]
Do you believe ethical considerations are an important part of an accountant's professional responsibilities? Why or why not? Think about this question, and then write notes according to the following outline. Use only the sections of the outline that are relevant to your position on this issue.
1. Ethical considerations are important to accountants because: (list your reasons)
2. Ethical considerations are not very important to accountants because: (list your reasons)
3. Accountants find guidance in making ethical decisions from the following sources: (list the sources you find)
In: Accounting